Popup_qui_marche_pas
Anthony RICHARD 2 years ago
parent e4348ec44d
commit cb1f33f32b

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

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

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

@ -5,12 +5,10 @@ namespace Model
public class Manager
{
public ObservableCollection<Game> GameList { get;}
private readonly IPersistance _persistance;
public Manager(IPersistance persistance)
{
_persistance = persistance;
GameList = _persistance.LoadGame();
GameList = persistance.LoadGame();
}
public void AddGametoGamesList(Game game)
@ -22,12 +20,5 @@ namespace Model
{
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.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace Model
{
@ -13,10 +8,7 @@ namespace Model
[DataMember]
public float Rate
{
get
{
return rate;
}
get => rate;
private set
{
if (value < 0 || value > 5) return;
@ -26,32 +18,23 @@ namespace Model
private float rate;
[DataMember]
public string Text
{
get
public string? Text
{
return text;
}
get => text;
private set
{
if (string.IsNullOrWhiteSpace(value)) return;
text = value;
}
}
private string text;
private string? text;
[DataMember]
public string AuthorName
{
get { return authorName; }
private set { authorName = value; }
}
private string authorName;
public string? AuthorName { get; set; }
public Review(/*string username,*/ float rate, string text)
public Review(string username, float rate, string text)
{
//AuthorName = username;
AuthorName = authorName;
AuthorName = username;
Rate = rate;
Text = text;
}
@ -60,16 +43,16 @@ namespace Model
public override string ToString()
{
return $"{AuthorName} : {Rate} : {Text}\n";
return $"{AuthorName} : {Rate} : {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
{
get { return username; }
get => username;
private set
{
if (string.IsNullOrWhiteSpace(value)) return;
@ -17,7 +17,7 @@ namespace Model
public string Biographie
{
get { return biographie;}
get => biographie;
private set
{
if (string.IsNullOrWhiteSpace(value)) return;
@ -28,7 +28,7 @@ namespace Model
public string Email
{
get { return email; }
get => email;
private set
{
Regex rg_email = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$");
@ -41,7 +41,7 @@ namespace Model
public string Password
{
get { return password; }
get => password;
private set
{
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)
{
game.AddReview(new Review(/*username,*/ rate, text));
game.AddReview(new Review(Username, rate, text));
}
public void RemoveSelfReview(Game game, float rate, string text)
{
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)

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

Loading…
Cancel
Save