From de4e761b5993b9d814015964a2a888f68accc866 Mon Sep 17 00:00:00 2001 From: Anthony RICHARD Date: Thu, 8 Jun 2023 20:24:33 +0200 Subject: [PATCH] modification commentaire --- Sources/Stim.Model/Game.cs | 8 +++++--- Sources/Stim/App.xaml | 11 ---------- Sources/Stim/DetailledPage.xaml | 15 ++++++++++++++ Sources/Stim/DetailledPage.xaml.cs | 10 ++++++++- Sources/Stim/MainPage.xaml.cs | 12 ++--------- Sources/Stim/ReviewPopUp.xaml.cs | 33 +++++++++++++++++++++++++----- 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/Sources/Stim.Model/Game.cs b/Sources/Stim.Model/Game.cs index 2100563..25c006a 100644 --- a/Sources/Stim.Model/Game.cs +++ b/Sources/Stim.Model/Game.cs @@ -150,15 +150,17 @@ namespace Model public void AddReview(Review review) { reviews.Add(review); - NotifyPropertyChanged(nameof(Reviews)); - NotifyPropertyChanged(nameof(Average)); + UpdateReviews(); } public void RemoveReview(Review review) { reviews.Remove(review); + UpdateReviews(); + } + public void UpdateReviews() + { NotifyPropertyChanged(nameof(Reviews)); NotifyPropertyChanged(nameof(Average)); - } public void DescChange(string newdesc) { diff --git a/Sources/Stim/App.xaml b/Sources/Stim/App.xaml index 3c149d8..d65a86f 100644 --- a/Sources/Stim/App.xaml +++ b/Sources/Stim/App.xaml @@ -28,17 +28,6 @@ - - - - - - - - diff --git a/Sources/Stim/DetailledPage.xaml b/Sources/Stim/DetailledPage.xaml index e86072c..e262a6c 100644 --- a/Sources/Stim/DetailledPage.xaml +++ b/Sources/Stim/DetailledPage.xaml @@ -6,6 +6,21 @@ Title="{Binding Name, FallbackValue='Default'}" Background="{StaticResource Secondary}"> + + + + + + + + + + + diff --git a/Sources/Stim/DetailledPage.xaml.cs b/Sources/Stim/DetailledPage.xaml.cs index 5dcb5a9..13b4f7f 100644 --- a/Sources/Stim/DetailledPage.xaml.cs +++ b/Sources/Stim/DetailledPage.xaml.cs @@ -19,7 +19,15 @@ public partial class DetailledPage : ContentPage private async void AddReview(object sender, EventArgs e) { - await this.ShowPopupAsync(new ReviewPopUp()); + var res = await this.ShowPopupAsync(new ReviewPopUp()); + if (res != null && res is int i && i == 1) await this.ShowPopupAsync(new MessagePopup("Commentaire ajouté !")); + } + + private async void EditReview(object sender, EventArgs e) + { + var res = await this.ShowPopupAsync(new ReviewPopUp((sender as ImageButton).BindingContext as Review)); + if (res != null && res is int i && i == 2) await this.ShowPopupAsync(new MessagePopup("Commentaire modifié !")); + } } private async void AddFollow(object sender, EventArgs e) diff --git a/Sources/Stim/MainPage.xaml.cs b/Sources/Stim/MainPage.xaml.cs index b6e0a9e..0297590 100644 --- a/Sources/Stim/MainPage.xaml.cs +++ b/Sources/Stim/MainPage.xaml.cs @@ -1,16 +1,8 @@ namespace Stim; using Model; -using StimPersistance; -using StimStub; -using Microsoft.Maui.Storage; -using MailKit.Search; -using System.Linq; -using System.Collections.Generic; public partial class MainPage : ContentPage { - public IEnumerable filterdGame { get; private set; } - public MainPage() { InitializeComponent(); @@ -19,8 +11,8 @@ public partial class MainPage : ContentPage private async void OnClickGameList(object sender, EventArgs e) { - (App.Current as App).Manager.SelectedGame = (sender as CollectionView).SelectedItem as Game; - await Navigation.PushAsync(new DetailledPage()); + (App.Current as App).Manager.SelectedGame = (sender as CollectionView).SelectedItem as Game; + await Navigation.PushAsync(new DetailledPage()); } private async void Addgame(object sender, EventArgs e) diff --git a/Sources/Stim/ReviewPopUp.xaml.cs b/Sources/Stim/ReviewPopUp.xaml.cs index cddbb6c..9dd5fcd 100644 --- a/Sources/Stim/ReviewPopUp.xaml.cs +++ b/Sources/Stim/ReviewPopUp.xaml.cs @@ -6,18 +6,28 @@ namespace Stim; public partial class ReviewPopUp : Popup { - public ReviewPopUp() + private readonly bool editing = false; + private Review prevRev = null; + public ReviewPopUp(Review previousRev = null) { InitializeComponent(); + if (previousRev != null) + { + prevRev = previousRev; + Entrytxt.Text = previousRev.Text; + Val.Text = previousRev.Rate.ToString(); + editing = true; + } } public void CloseButton(object sender, EventArgs e) { - Close(); + Close(0); } private void Valider(object sender, EventArgs e) { + int res; if ((App.Current as App).Manager.SelectedGame == null) { throw new Exception(); @@ -25,10 +35,23 @@ public partial class ReviewPopUp : Popup 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((App.Current as App).Manager.SelectedGame, rate, Entrytxt.Text); + //Error.Text = ""; + if (editing == true) + { + if (prevRev.Text != Entrytxt.Text) prevRev.EditReview(Entrytxt.Text); + prevRev.EditRate(rate); + (App.Current as App).Manager.SelectedGame.UpdateReviews(); + res = 2; + } + else + { + ((App)App.Current).Manager.CurrentUser.AddReview((App.Current as App).Manager.SelectedGame, rate, Entrytxt.Text); + res = 1; + } + ((App)App.Current).Manager.SaveGames(); - Close(); + Close(res); } - else Error.Children.Add(new Label { Text="Champ vide ou invalide", TextColor=Colors.Red }); + //else Error.Text = "Champ vide ou invalide"; } } \ No newline at end of file