utilisation de linq pour calculer l'average + modif en conséquence dans le xaml
continuous-integration/drone/push Build is failing Details

Popup_qui_marche_pas
Anthony RICHARD 2 years ago
parent 7e24778578
commit 2dd30cbced

@ -92,17 +92,7 @@ namespace Model
[DataMember] [DataMember]
public List<Review> Reviews { get; private init; } public List<Review> Reviews { get; private init; }
[DataMember] public double Average => Math.Round((double)Reviews.Select(review=>review.Rate).Average(), 1); // FAUT FIX POUR QUAND Y'A PAS DE REVIEWS
public float Average
{
get => average;
private set
{
average = value;
NotifyPropertyChanged();
}
}
private float average;
[DataMember] [DataMember]
public string? Lien { public string? Lien {
@ -133,7 +123,6 @@ namespace Model
if (string.IsNullOrWhiteSpace(c_lien)) Lien = "Default"; if (string.IsNullOrWhiteSpace(c_lien)) Lien = "Default";
else Lien = c_lien; else Lien = c_lien;
Reviews = new List<Review>(); Reviews = new List<Review>();
Average = 0;
} }
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
@ -179,26 +168,13 @@ namespace Model
return builder.ToString(); return builder.ToString();
} }
public float GetAvgRate()
{
float sum = 0;
foreach (Review review in Reviews)
{
sum += review.Rate;
}
Average= (float)(Math.Round((sum / Reviews.Count) * 2, MidpointRounding.AwayFromZero) / 2);
return Average;
}
public void AddReview(Review review) public void AddReview(Review review)
{ {
Reviews.Add(review); Reviews.Add(review);
Average = GetAvgRate();
} }
public void RemoveReview(Review review) public void RemoveReview(Review review)
{ {
Reviews.Remove(review); Reviews.Remove(review);
Average = GetAvgRate();
} }
public void DescChange(string newdesc) public void DescChange(string newdesc)
{ {

@ -58,7 +58,7 @@
<Label Grid.Column="1" Grid.Row="3" Text="{Binding Lien}"/> <Label Grid.Column="1" Grid.Row="3" Text="{Binding Lien}"/>
<HorizontalStackLayout Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="3" x:Name="starsContainer" HorizontalOptions="End"> <HorizontalStackLayout Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="3" x:Name="starsContainer" HorizontalOptions="End">
<Label Padding="0,5,0,0" FontSize="25" x:Name="avgLabel"/> <Label Padding="0,5,0,0" FontSize="25" Text="{Binding Average}"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<VerticalStackLayout Grid.ColumnSpan="4" Grid.Row="4"> <VerticalStackLayout Grid.ColumnSpan="4" Grid.Row="4">

@ -17,8 +17,7 @@ public partial class DetailledPage : ContentPage
if (currentGame is null) Navigation.PopAsync(); if (currentGame is null) Navigation.PopAsync();
else else
{ {
avgLabel.Text = currentGame.GetAvgRate().ToString(); AddStars(starsContainer, currentGame.Average);
AddStars(starsContainer, currentGame.GetAvgRate());
} }
} }
@ -29,7 +28,7 @@ public partial class DetailledPage : ContentPage
AddStars(layout, rev.Rate); AddStars(layout, rev.Rate);
} }
public static void AddStars(HorizontalStackLayout container, float rate) public static void AddStars(HorizontalStackLayout container, double rate)
{ {
for (int i = 0; i < (int)rate; i++) container.Children.Add(new Image { Source = "etoile_pleine.png", WidthRequest = 30 }); for (int i = 0; i < (int)rate; i++) container.Children.Add(new Image { Source = "etoile_pleine.png", WidthRequest = 30 });
if ((int)rate != rate) container.Children.Add(new Image { Source = "etoile_mi_pleine.png", WidthRequest = 30 }); if ((int)rate != rate) container.Children.Add(new Image { Source = "etoile_mi_pleine.png", WidthRequest = 30 });
@ -64,4 +63,21 @@ public partial class DetailledPage : ContentPage
await this.ShowPopupAsync(new MessagePopup("Jeu déjà suivis !")); await this.ShowPopupAsync(new MessagePopup("Jeu déjà suivis !"));
} }
} }
protected override void OnNavigatedFrom(NavigatedFromEventArgs args)
{
Navigation.PopAsync();
base.OnNavigatedFrom(args);
}
protected override void OnDisappearing()
{
Navigation.PopAsync();
base.OnDisappearing();
}
protected override void OnAppearing()
{
base.OnAppearing();
}
} }
Loading…
Cancel
Save