diff --git a/Sources/Persistance/Persistance.cs b/Sources/Persistance/Persistance.cs index 3477b85..107af76 100644 --- a/Sources/Persistance/Persistance.cs +++ b/Sources/Persistance/Persistance.cs @@ -28,7 +28,11 @@ namespace StimPersistance public void SaveUser(List users) { - throw new NotImplementedException(); + XmlWriterSettings settings = new() { Indent = true }; + DataContractSerializer serializer = new(typeof(List)); + + using (TextWriter tw = File.CreateText("users.xml")) + using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, users); } public ObservableCollection LoadGame() @@ -43,7 +47,12 @@ namespace StimPersistance public List LoadUser() { - throw new NotImplementedException(); + if (File.Exists("users.xml")) + { + DataContractSerializer serializer = new(typeof(List)); + using (Stream stream = File.OpenRead("users.xml")) return serializer.ReadObject(stream) as List; + } + return new(); } } } \ No newline at end of file diff --git a/Sources/Stim.Model/IPersistance.cs b/Sources/Stim.Model/IPersistance.cs index 22f4143..0717c75 100644 --- a/Sources/Stim.Model/IPersistance.cs +++ b/Sources/Stim.Model/IPersistance.cs @@ -8,5 +8,6 @@ namespace Model public void SaveUser(List users); public ObservableCollection LoadGame(); public List LoadUser(); + } } diff --git a/Sources/Stim.Model/Manager.cs b/Sources/Stim.Model/Manager.cs index 5985178..df31c11 100644 --- a/Sources/Stim.Model/Manager.cs +++ b/Sources/Stim.Model/Manager.cs @@ -8,6 +8,7 @@ namespace Model public ObservableCollection GameList { get;} public ObservableCollection ResearchedGame { get; set; } public User CurrentUser { get; set; } + public List Users { get; set; } public Manager(IPersistance persistance) { @@ -15,6 +16,7 @@ namespace Model CurrentUser = new User(null,"username", "je suis née .... maintenat je fini à 19h30 à cause de l'IHM. GHGHTFCDXEFTGHYJKIJHNGFVCREDTGHNJIKJUHNYGVTFCREDZTGYHUNJIKJUHNYTGVFCREDRTYHUJIOUJNHYGVFRCCFTGYHUJIUJNHYTGBVCFDRRTGYHUI", "email@email.com", "password88"); GameList = persistance.LoadGame(); ResearchedGame = persistance.LoadGame(); + Users = persistance.LoadUser(); if (GameList == null) { GameList = new ObservableCollection();} } @@ -23,6 +25,11 @@ namespace Model GameList.Add(game); Mgrpersistance.SaveGame(GameList); } + public void AddUsertoUserList(User user) + { + Users.Add(user); + Mgrpersistance.SaveUser(Users); + } public void RemoveGameFromGamesList(Game game) { @@ -34,5 +41,17 @@ namespace Model { Mgrpersistance.SaveGame(GameList); } + public User? SearchUser(string username) + { + foreach (User user in Users) + { + if (user.Username == username) return user; + } + return null; + } + public void SaveUser() + { + Mgrpersistance.SaveUser(Users); + } } } diff --git a/Sources/Stim.Model/User.cs b/Sources/Stim.Model/User.cs index 3c7837e..8cb89c3 100644 --- a/Sources/Stim.Model/User.cs +++ b/Sources/Stim.Model/User.cs @@ -1,11 +1,16 @@ using System.Collections.ObjectModel; using System.ComponentModel; +using System.Runtime.Serialization; +using System.Text; using System.Text.RegularExpressions; +using System.Xml.Linq; namespace Model { - public class User : INotifyPropertyChanged + [DataContract] + public class User : INotifyPropertyChanged , IEquatable { + [DataMember] public string Username { get => username; @@ -16,7 +21,7 @@ namespace Model } } private string username; - + [DataMember] public string Biographie { get => biographie; @@ -27,7 +32,7 @@ namespace Model } } private string biographie; - + [DataMember] public string Email { get => email; @@ -40,7 +45,7 @@ namespace Model } } private string email; - + [DataMember] public string Password { get => password; @@ -55,7 +60,7 @@ namespace Model public event PropertyChangedEventHandler? PropertyChanged; - + [DataMember] public ObservableCollection Followed_Games { get; @@ -86,6 +91,12 @@ namespace Model else Password = password; Followed_Games = new ObservableCollection(); } + public bool Equals(User? other) + { + if (string.IsNullOrWhiteSpace(Username)) return false; + return other != null && Username.Equals(other.Username); + } + public void AddReview(Game game, float rate, string text) { game.AddReview(new Review(Username, rate, text)); diff --git a/Sources/Stim/AddGamePage.xaml.cs b/Sources/Stim/AddGamePage.xaml.cs index a072a06..3f99154 100644 --- a/Sources/Stim/AddGamePage.xaml.cs +++ b/Sources/Stim/AddGamePage.xaml.cs @@ -1,7 +1,7 @@ using Model; using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; using Application = Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific.Application; -using Windows.Gaming.Preview.GamesEnumeration; +//using Windows.Gaming.Preview.GamesEnumeration; namespace Stim; diff --git a/Sources/Stim/App.xaml.cs b/Sources/Stim/App.xaml.cs index 07f36d8..9b20186 100644 --- a/Sources/Stim/App.xaml.cs +++ b/Sources/Stim/App.xaml.cs @@ -22,6 +22,7 @@ public partial class App : Application { Manager.Mgrpersistance = new Persistance(FileSystem.Current.AppDataDirectory); Manager.SaveGames(); + Manager.SaveUser(); }; return window; diff --git a/Sources/Stim/AppShell.xaml b/Sources/Stim/AppShell.xaml index df7b4c2..bd67d6d 100644 --- a/Sources/Stim/AppShell.xaml +++ b/Sources/Stim/AppShell.xaml @@ -10,6 +10,9 @@ > + diff --git a/Sources/Stim/Create.xaml b/Sources/Stim/Create.xaml new file mode 100644 index 0000000..2ed4b11 --- /dev/null +++ b/Sources/Stim/Create.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -54,16 +54,6 @@ - diff --git a/Sources/Stim/Stim.csproj b/Sources/Stim/Stim.csproj index 9115c82..66813cb 100644 --- a/Sources/Stim/Stim.csproj +++ b/Sources/Stim/Stim.csproj @@ -64,6 +64,12 @@ %(Filename) + + LoginPage.xaml + + + Create.xaml + UserInfo.xaml @@ -79,6 +85,12 @@ MSBuild:Compile + + MSBuild:Compile + + + MSBuild:Compile + MSBuild:Compile diff --git a/Sources/Stub/Stub.cs b/Sources/Stub/Stub.cs index 3f3096e..1ebfa0e 100644 --- a/Sources/Stub/Stub.cs +++ b/Sources/Stub/Stub.cs @@ -45,12 +45,14 @@ namespace StimStub public void SaveUser(List users) { - + foreach (User user in users) if (!users.Contains(user)) users.Add(user); } public List LoadUser() { - return null; + List tmp = new(); + + return tmp; } } } \ No newline at end of file