Implementazione funzione ingredienti per Server 1.0.1

This commit is contained in:
2026-02-26 09:33:42 +01:00
parent cb6c007480
commit 33be97e894
2 changed files with 42 additions and 2 deletions

View File

@@ -367,7 +367,7 @@ namespace PizzaExpress_Client
}
// ======================================================================
private void BtnIngredienti_Click(object? sender, EventArgs e)
private async void BtnIngredienti_Click(object? sender, EventArgs e)
{
if (_lstPizze.SelectedItem == null)
{
@@ -375,7 +375,32 @@ namespace PizzaExpress_Client
return;
}
MessageBox.Show("Funzionalità Ingredienti non ancora implementata.");
var pizza = _tutteLePizze[_lstPizze.SelectedIndex];
try
{
var dati = await _httpClient.GetFromJsonAsync<RispostaIngredienti>($"api/ingredienti/da-pizza?nome={pizza.Nome}");
if (dati == null)
{
MessageBox.Show("Errore nella risposta del server.");
return;
}
if (dati.ingredienti.Count == 0)
{
MessageBox.Show($"La pizza {dati.pizza} non ha ingredienti associati.");
return;
}
else
{
MessageBox.Show($"Ingredienti {dati.pizza}:\n- " + string.Join("\n- ", dati.ingredienti));
}
}
catch (Exception nigga)
{
MessageBox.Show($"{nigga.Message}", "Errore nella richiesta", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void PulisciCampi()

15
RispostaIngredienti.cs Normal file
View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PizzaExpress_Client
{
internal class RispostaIngredienti
{
public string pizza { get; set; }
public List<string> ingredienti { get; set; }
public string fonte { get; set; }
}
}