public bool Fusionner(int noPrestation1, int noPrestation2) { try { Prestation prestation1 = this[noPrestation1]; Prestation prestation2 = this[noPrestation2]; if (prestation1 == null || prestation2 == null) { throw new Exception("Nous n'avons pas pu fusionner les 2 prestations."); } Prestation nouvellePrestation = prestation1.Fusionner(prestation2); _prestations.Remove(prestation1); _prestations.Remove(prestation2); _prestations.Add(nouvellePrestation); return(true); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
//-- Méthodes d'instance public Prestation Fusionner(Prestation autre) { //string description = $"{NettoyerDescription(this.Description)} {NettoyerDescription(autre.Description)}"; //string description = String.Format( // "{0} {1}", // NettoyerDescription(this.Description), // NettoyerDescription(autre.Description)); string description = FormaterDescription(this.Description, autre.Description); int duree = this.DuréeEffective + autre.DuréeEffective; decimal tauxTva = Math.Min(this.TauxTva, autre.TauxTva); return(new Prestation(description, duree, tauxTva)); }
//-- Indexeur //public Prestation this[int numero] //{ // get { return _prestations.FirstOrDefault(prestation => prestation.Numero == numero); } //} public Prestation this[int numPrestation] { get { Prestation retVal = null; foreach (Prestation p in this) { if (p.Numero == numPrestation) { retVal = p; break; } } return(retVal); } }
public bool AjouterPrestation(string description, int duree, decimal tauxTva) { try { Prestation nouvellePrestation = new Prestation(description, duree, tauxTva); bool estSuperieurALimite = DureeTotale + duree > 360; if (estSuperieurALimite) { throw new Exception("La journée ne peut pas dépassé 6h."); } _prestations.Add(nouvellePrestation); return(true); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }