using ParionsCuite; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ParionsCuite.Modeles { /// /// Represents an event. /// [DataContract] public class Evenement : INotifyPropertyChanged { /// /// Event that is raised when a property value changes. /// public event PropertyChangedEventHandler? PropertyChanged; /// /// Raises the event for a specific property. /// /// The name of the property that changed. void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); /* Properties */ /// /// Gets or private sets the name of the event. /// [DataMember] public string Nom { get; private set; } /// /// Gets or private sets the date of the event. /// [DataMember] public string Date { get; private set; } /// /// Gets or private sets the location of the event. /// [DataMember] public string Lieu { get; private set; } /// /// Gets or private sets the time of the event. /// [DataMember] public string Heure { get; private set; } /// /// Gets the participation information for the event. /// [DataMember] public Participation Participation { get; private set; } /// /// Gets the list of invited guests for the event. /// [DataMember] public List ListInviter { get; private set; } /// /// Event that is raised when a bet is added to the event. /// public event Action PariAdd; /// /// Gets or private sets the list of bets for the event. /// [DataMember] private ObservableCollection listParier; /// /// Gets or sets the list of bets for the event. /// public ObservableCollection ListParier { get { return listParier; } set { if (listParier != value) { listParier = value; OnPropertyChanged(); OnPariAdded(value.LastOrDefault()); } } } /* Methods */ private void OnPariAdded(Parier parier) { // Logic to execute when a bet is added Debug.WriteLine("Bet added: "); } /// /// Adds a bet to the event. /// /// The bet to add. /// True if the bet was added successfully; otherwise, false. public bool Ajout_Pari(Parier pari) { ListParier.Add(pari); OnPropertyChanged(nameof(Parier)); PariAdd?.Invoke(pari); return true; } /// /// Initializes a new instance of the class with the specified name, date, location, and time. /// /// The name of the event. /// The date of the event. /// The location of the event. /// The time of the event. public Evenement(string nom, string date, string lieu, string heure) { Nom = nom; Date = date; Lieu = lieu; Heure = heure; ListInviter = new List(); ListParier = new ObservableCollection(); Participation = new Participation(); } /// /// Initializes a new instance of the class with the specified name, date, location, time, and participation information. /// /// The name of the event. /// The date of the event. /// The location of the event. /// The time of the event. /// The participation information for the event. public Evenement(string nom, string date, string lieu, string heure, Participation participation) { Nom = nom; Date = date; Lieu = lieu; Heure = heure; Participation = participation; ListInviter = new List(); ListParier = new ObservableCollection(); } /* Inviter methods */ /// /// Adds a guest to the event's list of invited guests. /// /// The guest to add. /// True if the guest was added successfully; otherwise, false. public bool Ajouter_inviter(Inviter I) { ListInviter.Add(I); foreach (Inviter i in ListInviter) { if (i == I) return true; } return false; } /// /// Removes a guest from the event's list of invited guests. /// /// The guest to remove. /// True if the guest was removed successfully; otherwise, false. public bool Supprimer_inviter(Inviter inviter) { return ListInviter.Remove(inviter); } /// /// Returns the number of invited guests in the event's list. /// /// The list of invited guests. /// The number of invited guests. public int LenListInvite(List list) { int len = 0; foreach (Inviter inviter in list) { len++; } return len; } /// /// Returns the list of invited guests for the event. /// /// The list of invited guests. public List ReturnListInvite() { return ListInviter; } /* Parie methods */ /// /// Adds a bet to the event's list of bets. /// /// The bet to add. /// True if the bet was added successfully; otherwise, false. public bool Ajouter_parie(Parier parier) { ListParier.Add(parier); foreach (Parier p in ListParier) { if (p == parier) return true; } return false; } /// /// Removes a bet from the event's list of bets. /// /// The bet to remove. /// True if the bet was removed successfully; otherwise, false. public bool Supprimer_parie(Parier p) { return ListParier.Remove(p); } /* Setter */ /// /// Sets the event's information. /// /// The name of the event. /// The date of the event. /// The location of the event. /// The time of the event. public void SetEvenement(string nom, string date, string lieu, string heure) { Nom = nom; Date = date; Lieu = lieu; Heure = heure; return; } /// /// Returns a string representation of the event. /// /// A string representation of the event. public override string ToString() { return $"Nom : {Nom} \nDate : {Date}\nLieu : {Lieu}\nHeure : {Heure} "; } } }