fix update ajout review + save review
continuous-integration/drone/push Build is failing Details

Popup_qui_marche_pas
Anthony RICHARD 2 years ago
parent 3812042ccb
commit 0bc4462aee

@ -74,8 +74,9 @@ namespace Model
}
private ObservableCollection<string> tags;
public ReadOnlyCollection<Review> Reviews => reviews.AsReadOnly();
[DataMember]
public ReadOnlyCollection<Review> Reviews { get; private set; }
private readonly List<Review> 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<Review>();
Reviews = new ReadOnlyCollection<Review>(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)
{

@ -7,7 +7,7 @@ namespace Model
public class Manager
{
public readonly IPersistance mgrpersistance;
public ReadOnlyCollection<Game> GameList { get; private set; }
public ReadOnlyCollection<Game> GameList => gameList.AsReadOnly();
private readonly List<Game> 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<Game>(gameList);
Users = persistance.LoadUser();
}

@ -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));
}

@ -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)

@ -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 });

Loading…
Cancel
Save