modification commentaire

master
Anthony RICHARD 2 years ago
parent 96463022eb
commit de4e761b59

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

@ -28,17 +28,6 @@
</Grid>
</Border>
</DataTemplate>
<DataTemplate x:Key="reviewTemplate">
<Border Margin="0, 5">
<VerticalStackLayout>
<Grid ColumnDefinitions="auto, *">
<Label Text="{Binding AuthorName, FallbackValue='Default'}" FontSize="20"/>
<local:StarsContainer Rate="{Binding Rate, FallbackValue='0'}" Grid.Column="2"/>
</Grid>
<Label Text="{Binding Text, FallbackValue='Default'}"/>
</VerticalStackLayout>
</Border>
</DataTemplate>
<DataTemplate x:Key="followTemplate">
<Border HeightRequest="150" Margin="10">
<Grid ColumnDefinitions="auto, *, 3*, auto" RowDefinitions="*">

@ -6,6 +6,21 @@
Title="{Binding Name, FallbackValue='Default'}"
Background="{StaticResource Secondary}">
<ContentPage.Resources>
<DataTemplate x:Key="reviewTemplate">
<Border Margin="0, 5">
<VerticalStackLayout>
<Grid ColumnDefinitions="auto, auto, auto, *">
<Label Text="{Binding AuthorName, FallbackValue='Default'}" FontSize="20"/>
<ImageButton Grid.Column="2" Source="pen.png" Background="{StaticResource Transparent}" HeightRequest="30" Clicked="EditReview"/>
<local:StarsContainer Grid.Column="4" Rate="{Binding Rate, FallbackValue='0'}"/>
</Grid>
<Label Text="{Binding Text, FallbackValue='Default'}"/>
</VerticalStackLayout>
</Border>
</DataTemplate>
</ContentPage.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />

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

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

@ -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";
}
}
Loading…
Cancel
Save