// Gets products where the price > 50 public List <Cosmétique> GetProduitsByPrice(Superette superette) { //var rec = from p in superette.Produits //where p.Prix > 50 //select p; //return rec.OfType<Cosmétique>().ToList(); return(superette.Produits.OfType <Cosmétique>().Where(p => p.Prix > 50).ToList()); }
public float GetCosPrice(Superette superette) { float sum = 0.0f; foreach (Cosmétique a in superette.Produits.OfType <Cosmétique>()) { sum += a.Prix; } return(sum); }
//total des prix ali cos d'une supp public float GetAlimentairePrice(Superette superette) { float sum = 0.0f; foreach (Alimentaire a in superette.Produits.OfType <Alimentaire>()) { sum += a.Prix; } return(sum); }
public Superette IsExpired(Superette superette) { //foreach (var p in superette.Produits.OfType<Alimentaire>()) //{ // if (p.DateExp < DateTime.Now) // { // return superette; // } //} //return null; return(superette.Produits.OfType <Alimentaire>().Where(p => p.DateExp < DateTime.Now) != null ? superette : null); }
public float GetTotal(Superette superette) { return(GetAlimentairePrice(superette) + GetCosPrice(superette)); }
// Returns the image of the logo of a of cosmétique of type perfum public string GetParfum(Superette superette) { return(superette.Produits.OfType <Cosmétique>().Where(p => p.Type == TypeCos.Parfum).FirstOrDefault()?.Logo.Image); }
// Get logo by superette public int GetLogoNbrBySup(Superette superette) { return(superette.Produits.Count); }
static void Main(string[] args) { Superette s = new Superette { Id = 1, Adresse = "Ghazela", Nom = "Chez Souhail", NumTel = 007, Logo = new Logo { Image = "img1", Description = "description" } }; Alimentaire a1 = new Alimentaire { Id = 1, Marque = "Délice", Nom = "Lait", Prix = 35, Logo = new Logo { Image = "lait1", Description = "lait" }, DateExp = DateTime.Now }; Alimentaire a2 = new Alimentaire { Id = 2, Marque = "Délice", Nom = "Délio", Prix = 67, Logo = new Logo { Image = "lait1", Description = "lait" }, DateExp = DateTime.Now }; Alimentaire a3 = new Alimentaire { Id = 3, Marque = "Délice", Nom = "Yaourt", Prix = 88, Logo = new Logo { Image = "lait1", Description = "lait" }, DateExp = DateTime.Now }; Cosmétique c1 = new Cosmétique { Id = 5, Marque = "c1", Nom = "c1", Prix = 300, Type = TypeCos.Parfum }; // Affectation à une liste s.Produits.Add(a1); s.Produits.Add(a2); s.Produits.Add(a3); s.Produits.Add(c1); // if p>50 => afficher // Avec foreach //foreach(Produit p in s.Produits) //{ // if(p.Prix > 50) // { // System.Console.WriteLine(p.Afficher()); // } //} // Avec Lambda exp //var list = s.Produits.Where(p => p.Prix > 50 // && p.Marque == "Délice"); // Afficher la marque du premier produit //System.Console.WriteLine(list.FirstOrDefault().Marque); // Avec Linq //var l = from p in s.Produits //where p.Prix > 50 && p.Marque == "Délice" //select p; // if produit of type gel and prix > 50 //var gels = from item in s.Produits.OfType<Cosmétique>() //where item.Prix > 50 && item.Type == TypeCos.Gel //select item; //foreach(Cosmétique c in gels) //{ // System.Console.WriteLine(c.Afficher()); //} //List<float> ListePrix = new List<float> //{ // a1.Prix, a2.Prix, a3.Prix, c1.Prix //}; //List<float> ListePrix = new List<float>(); //foreach (Produit p in s.Produits) //{ // ListePrix.Add(p.Prix); //} //// Pour ordonner la liste asc //ListePrix.Sort(); //// Pour la rendre ordonnée en dsc //ListePrix.Reverse(); //foreach(float p in ListePrix) //{ // System.Console.WriteLine(p); //} //foreach(Produit p in list) //{ // System.Console.WriteLine(p.Afficher()); //} //Service services = new Service(); //System.Console.WriteLine(services.GetParfum(s)); //var res = services.GetProduitsByPrice(s); //foreach (var p in res) //{ // System.Console.WriteLine(p.Nom); //} a1.Prix = float.Parse(System.Console.ReadLine()); try { if (a1.Prix < 0) { throw new PrixException(a1.Nom); } } catch (PrixException ex) { System.Console.WriteLine(ex.ToString()); } System.Console.ReadKey(); }