|
|
@ -6,10 +6,16 @@ using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Model
|
|
|
|
namespace Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Représente un jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[DataContract]
|
|
|
|
[DataContract]
|
|
|
|
public sealed class Game : INotifyPropertyChanged, IEquatable<Game>
|
|
|
|
public sealed class Game : INotifyPropertyChanged, IEquatable<Game>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient ou définit le nom du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public string Name
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => name;
|
|
|
|
get => name;
|
|
|
@ -23,6 +29,9 @@ namespace Model
|
|
|
|
private string name = default!;
|
|
|
|
private string name = default!;
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient ou définit la description du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public string Description
|
|
|
|
public string Description
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => description;
|
|
|
|
get => description;
|
|
|
@ -36,6 +45,9 @@ namespace Model
|
|
|
|
private string description = default!;
|
|
|
|
private string description = default!;
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient ou définit l'année de sortie du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public int Year
|
|
|
|
public int Year
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => year;
|
|
|
|
get => year;
|
|
|
@ -49,6 +61,9 @@ namespace Model
|
|
|
|
private int year = default!;
|
|
|
|
private int year = default!;
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient ou définit la couverture du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public string Cover
|
|
|
|
public string Cover
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => cover;
|
|
|
|
get => cover;
|
|
|
@ -61,6 +76,9 @@ namespace Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private string cover = default!;
|
|
|
|
private string cover = default!;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient les étiquettes du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public ReadOnlyCollection<string> Tags
|
|
|
|
public ReadOnlyCollection<string> Tags
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => tags.AsReadOnly();
|
|
|
|
get => tags.AsReadOnly();
|
|
|
@ -74,15 +92,25 @@ namespace Model
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private List<string> tags;
|
|
|
|
private List<string> tags;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient les avis sur le jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public ReadOnlyCollection<Review> Reviews => reviews.AsReadOnly();
|
|
|
|
public ReadOnlyCollection<Review> Reviews => reviews.AsReadOnly();
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private readonly List<Review> reviews;
|
|
|
|
private readonly List<Review> reviews;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient la note moyenne du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public double Average => Reviews.Any() ? Math.Round(Reviews.Select(review => review.Rate).Average(), 1) : 0;
|
|
|
|
public double Average => Reviews.Any() ? Math.Round(Reviews.Select(review => review.Rate).Average(), 1) : 0;
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
public string Lien {
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Obtient ou définit le lien du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public string Lien
|
|
|
|
|
|
|
|
{
|
|
|
|
get => lien;
|
|
|
|
get => lien;
|
|
|
|
private set
|
|
|
|
private set
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -93,6 +121,15 @@ namespace Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private string lien = default!;
|
|
|
|
private string lien = default!;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Initialise une nouvelle instance de la classe <see cref="Game"/> avec les valeurs spécifiées.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="name">Le nom du jeu.</param>
|
|
|
|
|
|
|
|
/// <param name="description">La description du jeu.</param>
|
|
|
|
|
|
|
|
/// <param name="year">L'année de sortie du jeu.</param>
|
|
|
|
|
|
|
|
/// <param name="c_tags">Les étiquettes du jeu.</param>
|
|
|
|
|
|
|
|
/// <param name="cover">La couverture du jeu.</param>
|
|
|
|
|
|
|
|
/// <param name="c_lien">Le lien du jeu.</param>
|
|
|
|
public Game(string name, string description, int year, List<string> c_tags, string cover, string c_lien)
|
|
|
|
public Game(string name, string description, int year, List<string> c_tags, string cover, string c_lien)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(name)) Name = "Default";
|
|
|
|
if (string.IsNullOrWhiteSpace(name)) Name = "Default";
|
|
|
@ -109,17 +146,29 @@ namespace Model
|
|
|
|
reviews = new List<Review>();
|
|
|
|
reviews = new List<Review>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Événement déclenché lorsque la valeur d'une propriété change.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
|
|
|
|
|
|
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
|
|
|
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
|
|
|
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Retourne le code de hachage pour l'objet.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns>Le code de hachage calculé.</returns>
|
|
|
|
public override int GetHashCode()
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(Name)) return 0;
|
|
|
|
if (string.IsNullOrWhiteSpace(Name)) return 0;
|
|
|
|
return Name.GetHashCode();
|
|
|
|
return Name.GetHashCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Détermine si l'objet spécifié est égal à l'objet actuel.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="obj">L'objet à comparer avec l'objet actuel.</param>
|
|
|
|
|
|
|
|
/// <returns>True si les objets sont égaux, sinon False.</returns>
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (object.ReferenceEquals(obj, null)) return false;
|
|
|
|
if (object.ReferenceEquals(obj, null)) return false;
|
|
|
@ -128,12 +177,21 @@ namespace Model
|
|
|
|
return this.Equals(obj as Game);
|
|
|
|
return this.Equals(obj as Game);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Détermine si l'objet spécifié est égal à l'objet actuel.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="other">L'objet à comparer avec l'objet actuel.</param>
|
|
|
|
|
|
|
|
/// <returns>True si les objets sont égaux, sinon False.</returns>
|
|
|
|
public bool Equals(Game? other)
|
|
|
|
public bool Equals(Game? other)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(Name)) return false;
|
|
|
|
if (string.IsNullOrWhiteSpace(Name)) return false;
|
|
|
|
return other != null && Name.Equals(other.Name);
|
|
|
|
return other != null && Name.Equals(other.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Retourne une chaîne qui représente l'objet courant.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns>Une chaîne qui représente l'objet courant.</returns>
|
|
|
|
public override string ToString()
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StringBuilder builder = new();
|
|
|
|
StringBuilder builder = new();
|
|
|
@ -147,33 +205,66 @@ namespace Model
|
|
|
|
return builder.ToString();
|
|
|
|
return builder.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Ajoute un avis sur le jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="review">L'avis à ajouter.</param>
|
|
|
|
public void AddReview(Review review)
|
|
|
|
public void AddReview(Review review)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
reviews.Add(review);
|
|
|
|
reviews.Add(review);
|
|
|
|
UpdateReviews();
|
|
|
|
UpdateReviews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Supprime un avis du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="review">L'avis à supprimer.</param>
|
|
|
|
public void RemoveReview(Review review)
|
|
|
|
public void RemoveReview(Review review)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
reviews.Remove(review);
|
|
|
|
reviews.Remove(review);
|
|
|
|
UpdateReviews();
|
|
|
|
UpdateReviews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Met à jour la liste des avis et la note moyenne.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public void UpdateReviews()
|
|
|
|
public void UpdateReviews()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NotifyPropertyChanged(nameof(Reviews));
|
|
|
|
NotifyPropertyChanged(nameof(Reviews));
|
|
|
|
NotifyPropertyChanged(nameof(Average));
|
|
|
|
NotifyPropertyChanged(nameof(Average));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Modifie la description du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="newdesc">La nouvelle description.</param>
|
|
|
|
public void DescChange(string newdesc)
|
|
|
|
public void DescChange(string newdesc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
description = newdesc;
|
|
|
|
description = newdesc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Modifie les étiquettes du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="newtag">La nouvelle liste d'étiquettes.</param>
|
|
|
|
public void TagChange(List<string> newtag)
|
|
|
|
public void TagChange(List<string> newtag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (newtag != null && newtag.Count <= 3) tags = new List<string>(newtag);
|
|
|
|
if (newtag != null && newtag.Count <= 3) tags = new List<string>(newtag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Modifie le nom du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="newname">Le nouveau nom.</param>
|
|
|
|
public void NameChange(string newname)
|
|
|
|
public void NameChange(string newname)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name = newname;
|
|
|
|
name = newname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Modifie l'année de sortie du jeu.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="newyear">La nouvelle année.</param>
|
|
|
|
public void YearChange(int newyear)
|
|
|
|
public void YearChange(int newyear)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
year = newyear;
|
|
|
|
year = newyear;
|
|
|
|