diff --git a/Sources/Stim.Model/Game.cs b/Sources/Stim.Model/Game.cs index df29884..2100563 100644 --- a/Sources/Stim.Model/Game.cs +++ b/Sources/Stim.Model/Game.cs @@ -74,8 +74,9 @@ namespace Model } private ObservableCollection tags; + public ReadOnlyCollection Reviews => reviews.AsReadOnly(); + [DataMember] - public ReadOnlyCollection Reviews { get; private set; } private readonly List reviews; public double Average => Reviews.Any() ? Math.Round(Reviews.Select(review => review.Rate).Average(), 1) : 0; @@ -106,7 +107,6 @@ namespace Model if (string.IsNullOrWhiteSpace(c_lien)) Lien = "Pas de lien"; else Lien = c_lien; reviews = new List(); - Reviews = new ReadOnlyCollection(reviews); } public event PropertyChangedEventHandler? PropertyChanged; @@ -150,10 +150,15 @@ namespace Model public void AddReview(Review review) { reviews.Add(review); + NotifyPropertyChanged(nameof(Reviews)); + NotifyPropertyChanged(nameof(Average)); } public void RemoveReview(Review review) { reviews.Remove(review); + NotifyPropertyChanged(nameof(Reviews)); + NotifyPropertyChanged(nameof(Average)); + } public void DescChange(string newdesc) { diff --git a/Sources/Stim.Model/Manager.cs b/Sources/Stim.Model/Manager.cs index 8ef7a73..af3e69f 100644 --- a/Sources/Stim.Model/Manager.cs +++ b/Sources/Stim.Model/Manager.cs @@ -7,7 +7,7 @@ namespace Model public class Manager { public readonly IPersistance mgrpersistance; - public ReadOnlyCollection GameList { get; private set; } + public ReadOnlyCollection GameList => gameList.AsReadOnly(); private readonly List gameList; public Game? SelectedGame { get; set; } public User? CurrentUser { get; set; } @@ -17,7 +17,6 @@ namespace Model { mgrpersistance = persistance; gameList = persistance.LoadGame(); - GameList = new ReadOnlyCollection(gameList); Users = persistance.LoadUser(); } diff --git a/Sources/Stim.Model/User.cs b/Sources/Stim.Model/User.cs index 7bd43f6..3566534 100644 --- a/Sources/Stim.Model/User.cs +++ b/Sources/Stim.Model/User.cs @@ -125,7 +125,7 @@ namespace Model return 0; } - public void AddReview(Game game, float rate, string text) + public void AddReview(Game game, double rate, string text) { game.AddReview(new Review(Username, rate, text)); } diff --git a/Sources/Stim/DetailledPage.xaml.cs b/Sources/Stim/DetailledPage.xaml.cs index 68acc78..5dcb5a9 100644 --- a/Sources/Stim/DetailledPage.xaml.cs +++ b/Sources/Stim/DetailledPage.xaml.cs @@ -8,8 +8,8 @@ public partial class DetailledPage : ContentPage public DetailledPage() { InitializeComponent(); - BindingContext = (App.Current as App).Manager.SelectedGame; if ((App.Current as App).Manager.SelectedGame is null) Navigation.RemovePage(this); + BindingContext = (App.Current as App).Manager.SelectedGame; } private async void GoToMainPage(object sender, EventArgs e) @@ -19,7 +19,7 @@ public partial class DetailledPage : ContentPage private async void AddReview(object sender, EventArgs e) { - await this.ShowPopupAsync(new ReviewPopUp((App.Current as App).Manager.SelectedGame)); + await this.ShowPopupAsync(new ReviewPopUp()); } private async void AddFollow(object sender, EventArgs e) diff --git a/Sources/Stim/ReviewPopUp.xaml.cs b/Sources/Stim/ReviewPopUp.xaml.cs index 1a8308b..cddbb6c 100644 --- a/Sources/Stim/ReviewPopUp.xaml.cs +++ b/Sources/Stim/ReviewPopUp.xaml.cs @@ -6,11 +6,9 @@ namespace Stim; public partial class ReviewPopUp : Popup { - Game CurrGame { get; set; } - public ReviewPopUp(Game currGame) + public ReviewPopUp() { InitializeComponent(); - CurrGame = currGame; } public void CloseButton(object sender, EventArgs e) @@ -20,14 +18,15 @@ public partial class ReviewPopUp : Popup private void Valider(object sender, EventArgs e) { - if (CurrGame == null) + if ((App.Current as App).Manager.SelectedGame == null) { throw new Exception(); } - bool IsFloat = float.TryParse(Val.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out float rate); - if (!string.IsNullOrWhiteSpace(Entrytxt.Text) && IsFloat) + bool isDouble = double.TryParse(Val.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out double rate); + if (!string.IsNullOrWhiteSpace(Entrytxt.Text) && isDouble) { - ((App)App.Current).Manager.CurrentUser.AddReview(CurrGame, rate, Entrytxt.Text); + ((App)App.Current).Manager.CurrentUser.AddReview((App.Current as App).Manager.SelectedGame, rate, Entrytxt.Text); + ((App)App.Current).Manager.SaveGames(); Close(); } else Error.Children.Add(new Label { Text="Champ vide ou invalide", TextColor=Colors.Red });