using Microsoft; using ParionsCuite; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ParionsCuite.Modeles { [DataContract] public class Participation { [DataMember] public List Boissons { get; private set; } [DataMember] public List Nourriture { get; private set; } [DataMember] public List Autre { get; private set; } /// /// Initializes a new instance of the class. /// public Participation() { Boissons = new List(); Nourriture = new List(); Autre = new List(); } /// /// Initializes a new instance of the class. /// /// The list of drinks. /// The list of food. /// The list of other items. public Participation(List boisson, List nourriture, List autre) { Boissons = boisson; Nourriture = nourriture; Autre = autre; } /* Boisson */ /// /// Adds a drink to the participation. /// /// The drink to add. /// true if the drink was added successfully; otherwise, false. public bool Ajout_Boissons(Boisson boisson) { foreach (var obj in Boissons) { if (obj.Equals(boisson)) { if (boisson.Quantite > 0) { obj.Quantite += boisson.Quantite; return true; } return false; } } Boissons.Add(boisson); return true; } /// /// Removes a specified quantity of a drink from the participation. /// /// The drink to remove. /// The quantity to remove. /// true if the drink was removed successfully; otherwise, false. public bool Sup_Boissons(Boisson boisson, int quantite) { foreach (var obj in Boissons) { if (obj.Equals(boisson)) { if (quantite > 0) { if (quantite >= boisson.Quantite) { Boissons.Remove(boisson); return true; } obj.Quantite -= quantite; return true; } return false; } } return false; } /* Nourriture */ /// /// Adds a food item to the participation. /// /// The food item to add. /// true if the food item was added successfully; otherwise, false. public bool Ajout_Nourriture(Nourriture food) { foreach (var obj in Nourriture) { if (obj.Equals(food)) { if (food.Quantite > 0) { obj.Quantite += food.Quantite; return true; } return false; } } Nourriture.Add(food); return true; } /// /// Removes a specified quantity of a food item from the participation. /// /// The food item to remove. /// The quantity to remove. /// true if the food item was removed successfully; otherwise, false. public bool Sup_Nourriture(Nourriture food, int quantite) { foreach (var obj in Nourriture) { if (obj.Equals(food)) { if (quantite > 0) { if (quantite >= food.Quantite) { Nourriture.Remove(food); return true; } obj.Quantite -= quantite; return true; } return false; } } return false; } /* Autre */ /// /// Adds another item to the participation. /// /// The other item to add. /// true if the other item was added successfully; otherwise, false. public bool Ajout_Autre(Autre autre) { foreach (var obj in Autre) { if (obj.Equals(autre)) { if (autre.Quantite > 0) { obj.Quantite += autre.Quantite; return true; } return false; } } Autre.Add(autre); return true; } /// /// Removes a specified quantity of another item from the participation. /// /// The other item to remove. /// The quantity to remove. /// true if the other item was removed successfully; otherwise, false. public bool Sup_Autre(Autre autre, int quantite) { foreach (var obj in Autre) { if (obj.Equals(autre)) { if (quantite > 0) { if (quantite >= autre.Quantite) { Autre.Remove(autre); return true; } obj.Quantite -= quantite; return true; } return false; } } return false; } } }