using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BowlingLib.Model { /// /// Classe Model Equipe /// public class Equipe:IEquatable { #region Propiéters public string Nom { get; private set; } public long Id { get; private set; } public ReadOnlyCollection Joueurs { get; private set; } private readonly List joueurs = new List(); #endregion #region Construteurs public Equipe(string nom) { Nom = nom; Joueurs = new ReadOnlyCollection(this.joueurs); } public Equipe(long id, string nom, params Joueur[] joueurs) { Id = id; Nom = nom; Joueurs = new ReadOnlyCollection(this.joueurs); AjouterJoueurs(joueurs); } public Equipe(string nom, params Joueur[] joueurs) : this(0, nom, joueurs) {} #endregion #region Méthodes /// /// Ajoute une liste de joueur à l'équipe /// /// /// public IEnumerable AjouterJoueurs(params Joueur[] joueurs) { List result = new(); result.AddRange(joueurs.Where(a => AjouterJoueur(a))); return result; } /// /// Ajouter un joueur s'il n'exciste pas dans la bd /// /// /// public bool AjouterJoueur(Joueur joueur) { if (!IsExist(joueur)) { joueurs.Add(joueur); return true; } else { return false; } } /// /// Supprimer un joueur /// /// public void SupprimerJoueur(Joueur joueur) { joueurs.Remove(joueur); } /// /// Fonction permettant de vérifier si un joueur existe déjà dans la liste (l'équipe) /// /// /// public bool IsExist(Joueur nouvJoueur) { if (joueurs.Contains(nouvJoueur)) return true; return false; } public override bool Equals(object obj) { if (ReferenceEquals(obj, null)) return false; if (ReferenceEquals(obj, this)) return true; if (GetType() != obj.GetType()) return false; return Equals(obj as Equipe); } public override int GetHashCode() { return joueurs.GetHashCode(); } public bool Equals(Equipe other) { return joueurs.Equals(other.joueurs); } #endregion } }