diff --git a/GestionePizzeForm.cs b/GestionePizzeForm.cs index 612c762..a1c4840 100644 --- a/GestionePizzeForm.cs +++ b/GestionePizzeForm.cs @@ -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($"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() diff --git a/RispostaIngredienti.cs b/RispostaIngredienti.cs new file mode 100644 index 0000000..fd33f58 --- /dev/null +++ b/RispostaIngredienti.cs @@ -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 ingredienti { get; set; } + public string fonte { get; set; } + } +}