namespace AziendaBibite; public class Azienda { public string NomeAzienda { get; private set; } private List inventario; private List clienti; private List vendite; public Azienda(string nomeAzienda) { NomeAzienda = nomeAzienda; inventario = new List(); clienti = new List(); vendite = new List(); } public void AggiungiBevanda(string nome, string listaIngredenti, int quantità, int gradazione) { AggiungiBevanda(new BevandaAlcolica(nome, listaIngredenti, quantità, gradazione)); } public void AggiungiBevanda(string nome, string listaIngredenti, int quantità, bool gassata) { AggiungiBevanda(new BevandaAnalcolica(nome, listaIngredenti, quantità, gassata)); } public void AggiungiBevanda(params Bevanda[] bevande) { inventario.AddRange(bevande); } public void AggiungiCliente(string ragioneSociale, string via, string città, string regione) { AggiungiCliente(new Cliente(ragioneSociale, via, città, regione)); } public void AggiungiCliente(params Cliente[] cliente) { clienti.AddRange(cliente); } public bool RegistraVendita(int codiceCliente, int codiceProdotto, int quantità) { return RegistraVendita(new Vendita(codiceCliente, codiceProdotto, quantità)); } public bool RegistraVendita(params Vendita[] vendita) { foreach (Vendita v in vendita) { if (!clienti.Any(x => x.Codice == v.CodiceCliente)) return false; if (!inventario.Any(x => x.Codice == v.CodiceProdotto)) return false; vendite.Add(v); } return true; } public string BevandeAcquistateDa(int codiceCliente) { string ret = String.Empty; foreach (Vendita v in vendite) { if (v.CodiceCliente == codiceCliente) { ret += v.CodiceProdotto + ", "; } } if (ret.Length > 2) return ret.Substring(0, ret.Length - 2); else return ret; } public string BibiteIngrediente(string ingrediente) { ingrediente = ingrediente.ToLower(); string ret = String.Empty; foreach (Bevanda bevanda in inventario) { if (bevanda.ListaIngredenti.ToLower().Contains(ingrediente)) { ret += "\t" + bevanda.Info() + "\n"; } } return ret.Length > 0 ? ret : "Nessuna bevanda trovata con questo ingrediente."; } public string InfoVendite() { if (vendite.Count == 0) return "Nessuna vendita registrata."; string ret = ""; foreach (Vendita v in vendite) { ret += "\t" + v.Info() + "\n"; } return ret; } public string Info() { string ret = "Bevande Alcoliche:\n"; foreach (Bevanda bevanda in inventario) { if (bevanda is BevandaAlcolica) { ret += "\t" + bevanda.Info() + "\n"; } } ret += "\nBevande Analcoliche:\n"; foreach (Bevanda bevanda in inventario) { if (bevanda is BevandaAnalcolica) { ret += "\t" + bevanda.Info() + "\n"; } } return ret; } }