You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Projet_IHM/Sources/Stim/ReviewPopUp.xaml.cs

62 lines
1.8 KiB

using CommunityToolkit.Maui.Views;
using Model;
using System.Globalization;
namespace Stim;
public partial class ReviewPopUp : Popup
{
private readonly bool editing = false;
private readonly 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(0);
}
private void Valider(object sender, EventArgs e)
{
int res;
if ((App.Current as App).Manager.SelectedGame == null)
{
throw new Exception();
}
bool isDouble = double.TryParse(Val.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out double rate);
if (!string.IsNullOrWhiteSpace(Entrytxt.Text) && isDouble)
{
if (rate < 0 || rate > 5) Error.Text = "Note invalide";
else
{
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(res);
}
}
else Error.Text = "Champ vide ou invalide";
}
}