Popup_qui_marche_pas
Anthony RICHARD 2 years ago
parent e4348ec44d
commit cb1f33f32b

@ -9,6 +9,7 @@ namespace StimPersistance
{ {
public Persistance() public Persistance()
{ {
//Faut refactor ce truc parce que c'est pas portable
Directory.SetCurrentDirectory("C:\\Users\\Admin\\source\\repos\\Projet_IHM\\Sources\\XML"); Directory.SetCurrentDirectory("C:\\Users\\Admin\\source\\repos\\Projet_IHM\\Sources\\XML");
} }
@ -23,18 +24,22 @@ namespace StimPersistance
public void SaveUser(List<User> users) public void SaveUser(List<User> users)
{ {
throw new NotImplementedException();
} }
public ObservableCollection<Game> LoadGame() public ObservableCollection<Game> LoadGame()
{
if (File.Exists("games.xml"))
{ {
DataContractSerializer serializer = new(typeof(ObservableCollection<Game>)); DataContractSerializer serializer = new(typeof(ObservableCollection<Game>));
using (Stream stream = File.OpenRead("games.xml")) return serializer.ReadObject(stream) as ObservableCollection<Game>; using (Stream stream = File.OpenRead("games.xml")) return serializer.ReadObject(stream) as ObservableCollection<Game>;
} }
return new();
}
public List<User> LoadUser() public List<User> LoadUser()
{ {
return null; throw new NotImplementedException();
} }
} }
} }

@ -1,6 +1,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text;
namespace Model namespace Model
{ {
@ -8,33 +9,33 @@ namespace Model
public class Game : INotifyPropertyChanged public class Game : INotifyPropertyChanged
{ {
[DataMember] [DataMember]
public string Name public string? Name
{ {
get { return name; } get => name;
private set private set
{ {
if (string.IsNullOrWhiteSpace(value)) return; if (string.IsNullOrWhiteSpace(value)) return;
name = value; name = value;
} }
} }
private string name; private string? name;
[DataMember] [DataMember]
public string Description public string? Description
{ {
get { return description; } get => description;
private set private set
{ {
if (string.IsNullOrWhiteSpace(value)) return; if (string.IsNullOrWhiteSpace(value)) return;
description = value; description = value;
} }
} }
private string description; private string? description;
[DataMember] [DataMember]
public int Year public int Year
{ {
get { return year; } get => year;
private set private set
{ {
if (value < 1957 || value > 2023) return; if (value < 1957 || value > 2023) return;
@ -44,7 +45,7 @@ namespace Model
private int year; private int year;
[DataMember] [DataMember]
public string Cover public string? Cover
{ {
get => cover; get => cover;
set set
@ -53,7 +54,7 @@ namespace Model
cover = value; cover = value;
} }
} }
private string cover; private string? cover;
[DataMember] [DataMember]
public ObservableCollection<string> Tags public ObservableCollection<string> Tags
@ -75,6 +76,7 @@ namespace Model
public Game() public Game()
{ {
tags = new ObservableCollection<string>();
Reviews = new List<Review>(); Reviews = new List<Review>();
Average = 0; Average = 0;
} }
@ -101,19 +103,20 @@ namespace Model
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
if ((obj == null) || !this.GetType().Equals(obj.GetType())) return false; if ((obj == null) || !this.GetType().Equals(obj.GetType())) return false;
return this.Name.Equals((obj as Game).Name) && this.Year.Equals((obj as Game).Year); return Name.Equals(((Game)obj).Name);
} }
public override string ToString() public override string ToString()
{ {
string s = $"{Name} : {Description} : {Year} : {Cover}\n"; StringBuilder builder = new();
builder.Append($"{Name} : {Description} : {Year} : {Cover}\n");
foreach(Review review in Reviews) foreach (Review review in Reviews)
{ {
s += review; builder.Append($"{review}\n");
} }
return s+"\n"; return builder.ToString();
} }
public float GetAvgRate() public float GetAvgRate()

@ -1,9 +1,4 @@
using System; using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model namespace Model
{ {

@ -5,12 +5,10 @@ namespace Model
public class Manager public class Manager
{ {
public ObservableCollection<Game> GameList { get;} public ObservableCollection<Game> GameList { get;}
private readonly IPersistance _persistance;
public Manager(IPersistance persistance) public Manager(IPersistance persistance)
{ {
_persistance = persistance; GameList = persistance.LoadGame();
GameList = _persistance.LoadGame();
} }
public void AddGametoGamesList(Game game) public void AddGametoGamesList(Game game)
@ -22,12 +20,5 @@ namespace Model
{ {
GameList.Remove(game); GameList.Remove(game);
} }
//J'ai commenté parce que je crois que la fonction est useless
//public void DelCom(Game game, Review review, int role)
//{
// if (role >= 1) game.RemoveReview(review);
//}
} }
} }

@ -1,9 +1,4 @@
using System; using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Model namespace Model
{ {
@ -13,10 +8,7 @@ namespace Model
[DataMember] [DataMember]
public float Rate public float Rate
{ {
get get => rate;
{
return rate;
}
private set private set
{ {
if (value < 0 || value > 5) return; if (value < 0 || value > 5) return;
@ -26,32 +18,23 @@ namespace Model
private float rate; private float rate;
[DataMember] [DataMember]
public string Text public string? Text
{
get
{ {
return text; get => text;
}
private set private set
{ {
if (string.IsNullOrWhiteSpace(value)) return; if (string.IsNullOrWhiteSpace(value)) return;
text = value; text = value;
} }
} }
private string text; private string? text;
[DataMember] [DataMember]
public string AuthorName public string? AuthorName { get; set; }
{
get { return authorName; }
private set { authorName = value; }
}
private string authorName;
public Review(/*string username,*/ float rate, string text) public Review(string username, float rate, string text)
{ {
//AuthorName = username; AuthorName = username;
AuthorName = authorName;
Rate = rate; Rate = rate;
Text = text; Text = text;
} }
@ -60,16 +43,16 @@ namespace Model
public override string ToString() public override string ToString()
{ {
return $"{AuthorName} : {Rate} : {Text}\n"; return $"{AuthorName} : {Rate} : {Text}";
} }
public void EditReview(string text) public void EditReview(string text)
{ {
Text = text+" (Modifié)"; if (!string.IsNullOrWhiteSpace(text)) Text = text+" (Modifié)";
} }
public void EditRate(int newval) public void EditRate(float newval)
{ {
rate= newval; Rate= newval;
} }
} }
} }

@ -6,7 +6,7 @@ namespace Model
{ {
public string Username public string Username
{ {
get { return username; } get => username;
private set private set
{ {
if (string.IsNullOrWhiteSpace(value)) return; if (string.IsNullOrWhiteSpace(value)) return;
@ -17,7 +17,7 @@ namespace Model
public string Biographie public string Biographie
{ {
get { return biographie;} get => biographie;
private set private set
{ {
if (string.IsNullOrWhiteSpace(value)) return; if (string.IsNullOrWhiteSpace(value)) return;
@ -28,7 +28,7 @@ namespace Model
public string Email public string Email
{ {
get { return email; } get => email;
private set private set
{ {
Regex rg_email = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"); Regex rg_email = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$");
@ -41,7 +41,7 @@ namespace Model
public string Password public string Password
{ {
get { return password; } get => password;
private set private set
{ {
Regex rg = new Regex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,32}$"); Regex rg = new Regex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,32}$");
@ -69,13 +69,13 @@ namespace Model
} }
public void AddReview(Game game, float rate, string text) public void AddReview(Game game, float rate, string text)
{ {
game.AddReview(new Review(/*username,*/ rate, text)); game.AddReview(new Review(Username, rate, text));
} }
public void RemoveSelfReview(Game game, float rate, string text) public void RemoveSelfReview(Game game, float rate, string text)
{ {
foreach (Review review in game.Reviews) foreach (Review review in game.Reviews)
{ {
if (review.Rate == rate && review.Text == text && review.AuthorName == username) game.RemoveReview(review); if (review.Rate == rate && review.Text == text && review.AuthorName == Username) game.RemoveReview(review);
} }
} }
public void FollowAGame(Game game) public void FollowAGame(Game game)

@ -73,7 +73,7 @@
<DataTemplate> <DataTemplate>
<VerticalStackLayout> <VerticalStackLayout>
<HorizontalStackLayout BindingContextChanged="AddStars"> <HorizontalStackLayout BindingContextChanged="AddStars">
<Label Text="Avis" FontSize="20"/> <Label Text="{Binding AuthorName}" FontSize="20"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<Label Text="{Binding Text}"/> <Label Text="{Binding Text}"/>
</VerticalStackLayout> </VerticalStackLayout>

Loading…
Cancel
Save