From 67245868b2f02232aa6bd97ffe2ddba15c698b13 Mon Sep 17 00:00:00 2001 From: Matheo THIERRY Date: Wed, 31 May 2023 16:32:26 +0200 Subject: [PATCH] debut huge upgrade --- notus/Biblioteque_de_Class/Database.cs | 53 ++++++------ notus/Biblioteque_de_Class/Exception.cs | 3 - notus/Biblioteque_de_Class/IManager.cs | 4 +- notus/Biblioteque_de_Class/Logo.cs | 10 +-- notus/Biblioteque_de_Class/Note.cs | 36 +++----- notus/Biblioteque_de_Class/NoteImage.cs | 14 +-- .../PersistenceManager.cs | 2 +- notus/Biblioteque_de_Class/Tags.cs | 9 +- notus/Biblioteque_de_Class/Theme.cs | 9 +- notus/Biblioteque_de_Class/User.cs | 85 ++++++++++--------- notus/Notus_Console/Program.cs | 49 ++++++----- notus/Notus_Persistence/Stub.cs | 24 +++--- notus/Notus_Persistence/ToJSON.cs | 3 +- 13 files changed, 132 insertions(+), 169 deletions(-) diff --git a/notus/Biblioteque_de_Class/Database.cs b/notus/Biblioteque_de_Class/Database.cs index fcf9fac..eadfcd8 100644 --- a/notus/Biblioteque_de_Class/Database.cs +++ b/notus/Biblioteque_de_Class/Database.cs @@ -14,27 +14,19 @@ namespace Biblioteque_de_Class public class Database { [DataMember] - private List DefaultLogoList; + public List DefaultLogoList { get; private set; } [DataMember] - private List ThemeList; + public List ThemeList { get; private set; } [DataMember] - private List UserList; - [DataMember] - private Dictionary> AddedThemeList; + public List UserList { get; private set; } public Database() { DefaultLogoList = new List(); ThemeList = new List(); UserList = new List(); - AddedThemeList = new Dictionary>(); } - public List GetDefaultLogoList() { return DefaultLogoList; } - public List GetThemeList() { return ThemeList; } - public List GetUserList() { return UserList; } - public Dictionary> GetAddedThemeFromUser() { return AddedThemeList; } - public void SetDefaultLogoList(List defaultLogoList) { DefaultLogoList = defaultLogoList; } public void SetDefaultThemeList(List defaultThemeList) { ThemeList = defaultThemeList; } @@ -45,7 +37,7 @@ namespace Biblioteque_de_Class { List searchedUsers = new List(); string search = name.ToLower(); - searchedUsers.AddRange(UserList.Where( user => user.GetUsername().ToLower().Contains(search))); + searchedUsers.AddRange(UserList.Where( user => user.Username.ToLower().Contains(search))); return searchedUsers; } @@ -56,7 +48,7 @@ namespace Biblioteque_de_Class { foreach (Logo logo in DefaultLogoList) { - if (logo.GetName() == name) { return logo.GetLogoLink(); } + if (logo.Name == name) { return logo.LogoLink; } } throw new NotFoundException("No logo link found."); } @@ -68,7 +60,7 @@ namespace Biblioteque_de_Class { foreach (User user in UserList) { - if (user.GetUsername() == name) + if (user.Username == name) { return user; } @@ -79,7 +71,7 @@ namespace Biblioteque_de_Class /// /// comparer le mot de passe entré avec celui de l'utilisateur /// - public static bool ComparePassword(User user, string? password) => user.GetPassword() == password; + public static bool ComparePassword(User user, string? password) => user.Password == password; /// /// rechercher un mail dans la liste d'utilisateur @@ -88,7 +80,7 @@ namespace Biblioteque_de_Class { foreach (User user in UserList) { - if (string.Equals(user.GetEmail(), email)) + if (string.Equals(user.Email, email)) { return true; } @@ -103,11 +95,11 @@ namespace Biblioteque_de_Class { foreach (User existingUser in UserList) { - if (existingUser.GetUsername() == user.GetUsername()) + if (existingUser.Username == user.Username) { throw new AlreadyUsedException("Username already used."); } - else if (existingUser.GetEmail() == user.GetEmail()) + else if (existingUser.Email == user.Email) { throw new AlreadyUsedException("Email already used."); } @@ -137,7 +129,7 @@ namespace Biblioteque_de_Class { foreach (Theme existingTheme in ThemeList) { - if (existingTheme.GetName() == theme.GetName()) + if (existingTheme.Name == theme.Name) { throw new AlreadyUsedException("Theme already used."); } @@ -152,7 +144,7 @@ namespace Biblioteque_de_Class { if (ThemeList.Contains(theme)) { - if (theme.GetName().Length > 6 && theme.GetName()[..6] != "Static" ) + if (theme.Name.Length > 6 && theme.Name[..6] != "Static" ) { throw new AlreadyUsedException("This theme is used a default theme."); } @@ -171,7 +163,7 @@ namespace Biblioteque_de_Class { foreach (Theme theme in ThemeList) { - if (theme.GetName() == name) + if (theme.Name == name) { return theme; } @@ -186,9 +178,9 @@ namespace Biblioteque_de_Class { foreach (Theme existingTheme in ThemeList) { - if (existingTheme.GetName() == theme.GetName()) + if (existingTheme.Name == theme.Name) { - existingTheme.SetName(newName); + existingTheme.Name = newName; return; } } @@ -202,20 +194,27 @@ namespace Biblioteque_de_Class { foreach (Theme existingTheme in ThemeList) { - if (existingTheme.GetName() == theme.GetName()) + if (existingTheme.Name == theme.Name) { for (int i = 0; i < 3; i++) { - existingTheme.ChangeColor(existingTheme.GetColor(i), newColorList[i]); + existingTheme.ChangeColor(existingTheme.ColorList[i], newColorList[i]); } return; } } } - public List AddedThemeOfOneUser(User user) + public void ChangeUsername(User user, string newUsername) { - return GetAddedThemeFromUser()[user]; + foreach(User existingUser in UserList) + { + if(existingUser.Username == user.Username) + { + throw new AlreadyUsedException("this username is already used."); + } + } + user.Username = newUsername; } } } \ No newline at end of file diff --git a/notus/Biblioteque_de_Class/Exception.cs b/notus/Biblioteque_de_Class/Exception.cs index 2cfe24d..fb033a2 100644 --- a/notus/Biblioteque_de_Class/Exception.cs +++ b/notus/Biblioteque_de_Class/Exception.cs @@ -48,9 +48,6 @@ namespace Biblioteque_de_Class } } - - - [Serializable] public class FileException : Exception { diff --git a/notus/Biblioteque_de_Class/IManager.cs b/notus/Biblioteque_de_Class/IManager.cs index 2b472a8..91a8912 100644 --- a/notus/Biblioteque_de_Class/IManager.cs +++ b/notus/Biblioteque_de_Class/IManager.cs @@ -8,10 +8,8 @@ namespace Biblioteque_de_Class { public interface IManager { - public void SaveDatabaseData(List UserList, Dictionary> AddedThemeFromUser); - + public void SaveDatabaseData(List UserList); public Database LoadDatabaseData(); - public List LoadDefaultTheme(); public List LoadDefaultLogo(); } diff --git a/notus/Biblioteque_de_Class/Logo.cs b/notus/Biblioteque_de_Class/Logo.cs index 7baf505..30d74dd 100644 --- a/notus/Biblioteque_de_Class/Logo.cs +++ b/notus/Biblioteque_de_Class/Logo.cs @@ -8,8 +8,8 @@ namespace Biblioteque_de_Class { public class Logo { - private string Name { get; set; } - private string LogoLink { get; set; } + public string Name { get; set; } + public string LogoLink { get; set; } public Logo(string name, string logoLink) { @@ -17,12 +17,6 @@ namespace Biblioteque_de_Class LogoLink = logoLink; } - public string GetName() { return Name; } - public string GetLogoLink() { return LogoLink; } - - public void SetName(string name) { Name = name; } - public void SetLogoLink(string logoLink) { LogoLink = logoLink; } - public override string ToString() => $"Logo -> Name: {Name}\nLink: {LogoLink}"; } } diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index 70f2893..9919301 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -16,11 +16,11 @@ namespace Biblioteque_de_Class public string Name { get { return name; } - private set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } + set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } } [DataMember] - private string Text { get; set; } = ""; + public string Text { get; private set; } = ""; [DataMember] private string logoPath; @@ -32,17 +32,17 @@ namespace Biblioteque_de_Class } [DataMember] - private DateOnly CreationDate { get; } + public DateOnly CreationDate { get; init; } [DataMember] - private DateOnly ModificationDate { get; set; } + public DateOnly ModificationDate { get; private set; } [DataMember] - private readonly List ImageList; + public List ImageList { get; private set; } [DataMember] - private readonly List Collaborators; + public List Collaborators { get; private set; } [DataMember] - private readonly List Editors; + public List Editors { get; private set; } [DataMember] - private readonly User Owner; + public User Owner { get; private set; } public Note(string name, string logoPath, User owner) { @@ -56,22 +56,8 @@ namespace Biblioteque_de_Class Owner = owner; } - public string GetName() { return Name; } - public string GetLogoPath() { return LogoPath; } - public string GetText() { return Text; } - public DateOnly GetCreationDate() { return CreationDate; } - public DateOnly GetModificationDate() { return ModificationDate; } - public List GetImageList() { return ImageList; } - public List GetCollaborators() { return Collaborators; } - public List GetEditors() { return Editors; } - public User GetOwner() { return Owner; } - public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}"; - public void SetName(string name) { Name = name; } - public void SetLogoPath(string logoPath) { LogoPath = logoPath; } - public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); } - /// /// vérifier si l'utilisateur est le propriétaire de la note /// @@ -90,7 +76,7 @@ namespace Biblioteque_de_Class { foreach (NoteImage image in ImageList) { - if (image.GetName() == name) + if (image.Name == name) { ImageList.Remove(image); return; @@ -119,7 +105,7 @@ namespace Biblioteque_de_Class { if (VerifyOwner(owner)) { Collaborators.Add(user); } else { throw new NotAllowedException("User is not the owner"); } - user.GetNoteList().Add(this); + user.NoteList.Add(this); } /// @@ -129,7 +115,7 @@ namespace Biblioteque_de_Class { if (VerifyOwner(owner)) { Collaborators.Remove(user); } else { throw new NotAllowedException("User is not the owner"); } - user.GetNoteList().Remove(this); + user.NoteList.Remove(this); } /// diff --git a/notus/Biblioteque_de_Class/NoteImage.cs b/notus/Biblioteque_de_Class/NoteImage.cs index 1680e74..267c246 100644 --- a/notus/Biblioteque_de_Class/NoteImage.cs +++ b/notus/Biblioteque_de_Class/NoteImage.cs @@ -8,9 +8,9 @@ namespace Biblioteque_de_Class { public class NoteImage { - private int Name { get; set; } - private string ImageLink { get; set; } - private string Position { get; set; } + public int Name { get; set; } + public string ImageLink { get; set; } + public string Position { get; set; } public NoteImage(int name, string imageLink, string position) { @@ -19,14 +19,6 @@ namespace Biblioteque_de_Class Position = position; } - public int GetName() { return Name; } - public string GetImageLink() { return ImageLink; } - public string GetPosition() { return Position; } - - public void SetName(int name) { Name = name; } - public void SetImageLink(string imageLink) { ImageLink = imageLink; } - public void SetPosition(string position) { Position = position; } - public override string ToString() => $"image -> name: {Name}\nlink: {ImageLink}"; } } diff --git a/notus/Biblioteque_de_Class/PersistenceManager.cs b/notus/Biblioteque_de_Class/PersistenceManager.cs index bee3338..030aa41 100644 --- a/notus/Biblioteque_de_Class/PersistenceManager.cs +++ b/notus/Biblioteque_de_Class/PersistenceManager.cs @@ -15,7 +15,7 @@ namespace Biblioteque_de_Class public void SaveDatabaseData(Database database) { - persistence.SaveDatabaseData(database.GetUserList(), database.GetAddedThemeFromUser()); + persistence.SaveDatabaseData(database.UserList); } public Database LoadDatabaseData() diff --git a/notus/Biblioteque_de_Class/Tags.cs b/notus/Biblioteque_de_Class/Tags.cs index dbba2b4..a0c4ec2 100644 --- a/notus/Biblioteque_de_Class/Tags.cs +++ b/notus/Biblioteque_de_Class/Tags.cs @@ -8,8 +8,8 @@ namespace Biblioteque_de_Class { public class Tags { - private string Name { get; set; } - private string Color { get; set; } + public string Name { get; set; } + public string Color { get; set; } public Tags(string name, string color) { @@ -17,11 +17,6 @@ namespace Biblioteque_de_Class Color = color; } - public string GetName() { return Name; } - public string GetColor() { return Color; } - public void SetName(string name) { Name = name; } - public void SetColor(string color) { Color = color; } - public override string ToString() => $"tag -> name: {Name}\ncolor: {Color}"; } } diff --git a/notus/Biblioteque_de_Class/Theme.cs b/notus/Biblioteque_de_Class/Theme.cs index 6a6f54a..15f16e7 100644 --- a/notus/Biblioteque_de_Class/Theme.cs +++ b/notus/Biblioteque_de_Class/Theme.cs @@ -8,8 +8,8 @@ namespace Biblioteque_de_Class { public class Theme { - private string Name { get; set; } - private readonly List ColorList; + public string Name { get; set; } + public List ColorList { get; private set; } public Theme(string name, List colorList) { @@ -17,11 +17,6 @@ namespace Biblioteque_de_Class ColorList = colorList; } - public string GetName() { return Name; } - public void SetName(string name) { Name = name; } - public List GetColorList() { return ColorList; } - public string GetColor(int index) { return ColorList[index]; } - public override string ToString() => $"name: {Name}\ncolor 1: {ColorList[0]}\ncolor 2: {ColorList[1]}\ncolor 3: {ColorList[2]}\n"; /// diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs index 20b6d5c..eccf052 100644 --- a/notus/Biblioteque_de_Class/User.cs +++ b/notus/Biblioteque_de_Class/User.cs @@ -9,25 +9,26 @@ namespace Biblioteque_de_Class public class User { [DataMember] - private string Username { get; set; } + public string Username { get; set; } [DataMember] - private string Email { get; set; } + public string Email { get; private set; } [DataMember] - private string Password { get; set; } + public string Password { get; private set; } [DataMember] - private string Picture { get; set; } + public string Picture { get; private set; } [DataMember] - private Theme Theme; + public Theme UseTheme { get; set; } [DataMember] - private List NoteList; + public List NoteList { get; set; } [DataMember] - private List TagList; + public List TagList { get; private set; } [DataMember] - private List FavList; + public List FavList { get; private set; } [DataMember(EmitDefaultValue = false)] - private bool IsConnected { get; set; } + public bool IsConnected { get; set; } [DataMember] - private Dictionary> NoteTagged; + public Dictionary> NoteTagged { get; set; } + public List AddedTheme { get; set; } public User(string username, string email, string password) { @@ -41,25 +42,6 @@ namespace Biblioteque_de_Class NoteTagged = new Dictionary>(); } - public string GetUsername() { return Username; } - public string GetEmail() { return Email; } - public string GetPassword() { return Password; } - public string GetPicture() { return Picture;} - public Theme GetTheme() { return Theme; } - public List GetNoteList() { return NoteList; } - public List GetTagList() { return TagList; } - public List GetFavList() { return FavList; } - public bool GetIsConnected() { return IsConnected; } - public Dictionary> GetNoteTagged() { return NoteTagged; } - public List GetNoteTaggedList(Note note) { return NoteTagged[note]; } - - public void SetUsername(string username) { Username = username; } - public void SetEmail(string email) { Email = email; } - public void SetPassword(string password) { Password = password; } - public void SetPicture(string picture) { Picture = picture; } - public void SetTheme(Theme theme) { Theme = theme; } - public void SetIsConnected(bool isConnected) { IsConnected = isConnected; } - public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}"; /// @@ -71,7 +53,7 @@ namespace Biblioteque_de_Class string search = name.ToLower(); foreach (Note note in ToResearchIntoList) { - if (note.GetName().ToLower().Contains(search)) + if (note.Name.ToLower().Contains(search)) { searchedNotes.Add(note); } @@ -88,7 +70,7 @@ namespace Biblioteque_de_Class string search = name.ToLower(); foreach (Tags tag in ToResearchIntoList) { - if (tag.GetName().ToLower().Contains(search)) + if (tag.Name.ToLower().Contains(search)) { searchedTags.Add(tag); } @@ -102,7 +84,7 @@ namespace Biblioteque_de_Class string search = name.ToLower(); foreach (Note note in ToResearchIntoList) { - if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate || note.GetModificationDate() >= FirstDate && note.GetModificationDate() <= SecondeDate) + if (note.Name.ToLower().Contains(search) && note.CreationDate >= FirstDate && note.CreationDate <= SecondeDate || note.ModificationDate >= FirstDate && note.ModificationDate <= SecondeDate) { searchedNotes.Add(note); } @@ -114,7 +96,7 @@ namespace Biblioteque_de_Class { foreach (Note note in NoteList) { - if (note.GetName() == name) + if (note.Name == name) { return note; } @@ -126,7 +108,7 @@ namespace Biblioteque_de_Class { foreach (Tags tag in TagList) { - if (tag.GetName() == name) + if (tag.Name == name) { return tag; } @@ -168,7 +150,7 @@ namespace Biblioteque_de_Class { foreach (Note existingNote in NoteList) { - if (existingNote.GetName() == name) + if (existingNote.Name == name) { throw new AlreadyExistException("Note already exists"); } @@ -185,7 +167,7 @@ namespace Biblioteque_de_Class { foreach (Note existingNote in NoteList) { - if (existingNote.GetName() == note) + if (existingNote.Name == note) { NoteList.Remove(existingNote); NoteTagged.Remove(existingNote); @@ -202,7 +184,7 @@ namespace Biblioteque_de_Class { foreach (Tags tag in TagList) { - if (tag.GetName() == name) + if (tag.Name == name) { throw new AlreadyExistException("Tag already exists"); } @@ -217,7 +199,7 @@ namespace Biblioteque_de_Class { foreach (Tags tag in TagList) { - if (tag.GetName() == name) + if (tag.Name == name) { TagList.Remove(tag); return; @@ -273,5 +255,32 @@ namespace Biblioteque_de_Class NoteTagged.Remove(note); } + public void SetNoteName(Note note, string newname) + { + foreach(Note n in NoteList) + { + if(n.Name == note.Name) + { + throw new AlreadyUsedException("This name is already used"); + } + } + note.Name = newname; + } + + public void ChangePassword(string newpassword) + { + if (newpassword == null) { return; } + if ( Password == newpassword) { throw new AlreadyExistException("this username is the same."); } + Password = newpassword; + } + + public void ChangeTheme(Theme theme) + { + if (UseTheme.Name == theme.Name) + { + throw new AlreadyExistException("this theme is already selectec."); + } + UseTheme = theme; + } } } \ No newline at end of file diff --git a/notus/Notus_Console/Program.cs b/notus/Notus_Console/Program.cs index bdc9bbe..68d0451 100644 --- a/notus/Notus_Console/Program.cs +++ b/notus/Notus_Console/Program.cs @@ -17,8 +17,7 @@ bool note=false, tags=false, para=false, paraCompte=false, theme=false; // déclaration d'un user qui sera utiliser pour servir de personne connecté dans l'app User u = new("", "", ""); -User uvide = new("", "", ""); -uvide.SetIsConnected(false); +User uvide = new("", "", "") { IsConnected = false }; // déclaration d'une note qui sera utiliser pour servir de note selectionnée Note n = new("","",uvide); @@ -65,25 +64,25 @@ bool choix_note() void displayNote() { - foreach (Note note in u.GetNoteList()) + foreach (Note note in u.NoteList) { - Console.WriteLine(note.GetName() + "\n"); + Console.WriteLine(note.Name + "\n"); } } void displayTag() { - foreach (Tags tag in u.GetTagList()) + foreach (Tags tag in u.TagList) { - Console.WriteLine(tag.GetName() + "\n"); + Console.WriteLine(tag.Name + "\n"); } } void displayTheme() { - foreach (Theme theme in db.GetThemeList()) + foreach (Theme theme in u.AddedTheme) { - Console.WriteLine(theme.GetName() + "\n"); + Console.WriteLine(theme.Name + "\n"); } } @@ -183,7 +182,7 @@ while (menu) { if (Database.ComparePassword(u, password.GetHashCode().ToString())) { - u.SetIsConnected(true); + u.IsConnected = true; Console.WriteLine("\nConnection réussie !\n"); menu = false; } @@ -215,7 +214,7 @@ while (menu) { u = new User(nom, "", password.GetHashCode().ToString()); db.AddUser(u); - db.GetUser(nom).SetIsConnected(true); + db.GetUser(nom).IsConnected = true; Console.WriteLine("\nConnection réussie !\n"); menu = false; break; @@ -226,7 +225,7 @@ while (menu) } } //une fois connecté ou inscription fait -while (u.GetIsConnected()) +while (u.IsConnected) { Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("| |"); @@ -245,7 +244,7 @@ while (u.GetIsConnected()) switch (Console.ReadLine()) { case "1": - researchlist = u.GetNoteList(); + researchlist = u.NoteList; Console.WriteLine("\nEntrez la note que vous cherchez. "); string? wantedSearchNote = Console.ReadLine(); Console.WriteLine("\nChercher par tags ? (o/N) "); @@ -263,7 +262,7 @@ while (u.GetIsConnected()) break; case "5": Console.WriteLine("\ndéconnecté! \n"); - u.SetIsConnected(false); + u.IsConnected = false; u = uvide; break; default: @@ -288,7 +287,7 @@ while (u.GetIsConnected()) Console.WriteLine("| 7/ - retour - |"); Console.WriteLine("| |"); Console.WriteLine("|-----------------------------------------------|\n"); - Console.WriteLine("note actuelle : " + n.GetName()); + Console.WriteLine("note actuelle : " + n.Name); Console.WriteLine("rentrez votre choix."); switch (Console.ReadLine()) { @@ -297,19 +296,19 @@ while (u.GetIsConnected()) break; case "2": if (!choix_note()) { break; } - Console.WriteLine("\n" + n.GetName() + " :"); - Console.WriteLine(n.GetText()); + Console.WriteLine("\n" + n.Name + " :"); + Console.WriteLine(n.Text); break; case "3": if (!choix_note()) { break;} Console.WriteLine("\nChoisissez le nouveau nom de la note (entrer - nom par defaut)"); string? wantedNewNameNote = Console.ReadLine(); wantedNewNameNote??= ""; - n.SetName(wantedNewNameNote); + u.SetNoteName(n, wantedNewNameNote); break; case "4": if (!choix_note()) { break; } - Console.WriteLine(n.GetText()); + Console.WriteLine(n.Text); Console.WriteLine("\nEntrez le texte à ajouter"); string? wantedTextNote = Console.ReadLine(); wantedTextNote??= ""; @@ -360,7 +359,7 @@ while (u.GetIsConnected()) case "1": Console.WriteLine("\nChoisissez le nom du tag."); string? wantedNameTag = Console.ReadLine(); - wantedNameTag??= "NoName" + u.GetTagList().Count.ToString(); + wantedNameTag??= "NoName" + u.NoteList.Count.ToString(); Console.WriteLine("\nChoisissez la couleur du tag."); string? wantedColorTag = Console.ReadLine(); wantedColorTag??= "#000000"; @@ -428,9 +427,9 @@ while (u.GetIsConnected()) try{ wantedRemoveNote = u.GetNoteByName(wantedRemoveNameNote); }catch (Exception ex) { Console.WriteLine(ex.Message); break;} - foreach( Tags t in u.GetNoteTaggedList(wantedRemoveNote)) + foreach( Tags t in u.NoteTagged[wantedRemoveNote]) { - Console.WriteLine(t.GetName() + "\n"); + Console.WriteLine(t.Name + "\n"); } Console.WriteLine("\nChoisissez le nom du tag à supprimer."); string? wantedRemoveNameTag = Console.ReadLine(); @@ -516,7 +515,7 @@ while (u.GetIsConnected()) Console.WriteLine("\nChoisissez le nouveau pseudo."); string? wantedNewPseudo = Console.ReadLine(); if(wantedNewPseudo == null){break;} - u.SetUsername(wantedNewPseudo); + db.ChangeUsername(u,wantedNewPseudo); break; case "2": Console.WriteLine("\nChoisissez le nouveau mot de passe."); @@ -526,11 +525,11 @@ while (u.GetIsConnected()) Console.WriteLine("\nLe mot de passe doit contenir au moins 8 caractères.\n"); break; } - if(wantedNewPassword.GetHashCode().ToString() == u.GetPassword()){ + if(wantedNewPassword.GetHashCode().ToString() == u.Password){ Console.WriteLine("\nLe nouveau mot de passe doit être différent de l'ancien.\n"); break; } - u.SetPassword(wantedNewPassword); + u.ChangePassword(wantedNewPassword); break; case "3": paraCompte = false; @@ -568,7 +567,7 @@ while (u.GetIsConnected()) { twantedTheme = db.GetTheme(wantedTheme); }catch (Exception ex) { Console.WriteLine(ex.Message); break;} - u.SetTheme(twantedTheme); + u.ChangeTheme(twantedTheme); break; case "2": List? themeList; diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs index fb8ed2c..7ca5cac 100644 --- a/notus/Notus_Persistence/Stub.cs +++ b/notus/Notus_Persistence/Stub.cs @@ -12,7 +12,7 @@ namespace Notus_Persistance { public class Stub : IManager { - public void SaveDatabaseData(List UserList, Dictionary> AddedThemeFromUser) + public void SaveDatabaseData(List UserList) { throw new NotImplementedException(); } @@ -31,7 +31,7 @@ namespace Notus_Persistance database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois")); // add some notes and tags to go faster - foreach(User user in database.GetUserList().Where(x => x.GetUsername().Contains("m"))) + foreach(User user in database.UserList.Where(x => x.Username.Contains("m"))) { user.CreateNote("Note 1", ""); user.CreateNote("Note 2", ""); @@ -41,19 +41,19 @@ namespace Notus_Persistance } // add note to user for sharing note test mixed with tag - uselect = (User)database.GetUserList().Where(x => x.GetUsername() == "Nicolas"); + uselect = (User)database.UserList.Where(x => x.Username == "Nicolas"); uselect.CreateNote("Note 4", "Logo_1"); uselect.CreateTag("Tag 3", "#00FF00"); - nselect = (Note)uselect.GetNoteList().Where(x => x.GetName() == "Note 4"); - uselect.AddTagToNoteList(nselect, (Tags)uselect.GetTagList().Where(x => x.GetName() == "Tag 3")); - nselect.AddCollaborator(uselect,(User)database.GetUserList().Where(x => x.GetUsername() == "Benjamin")); - uselect = (User)database.GetUserList().Where(x => x.GetUsername() == "Benjamin"); + nselect = (Note)uselect.NoteList.Where(x => x.Name == "Note 4"); + uselect.AddTagToNoteList(nselect, (Tags)uselect.TagList.Where(x => x.Name == "Tag 3")); + nselect.AddCollaborator(uselect,(User)database.UserList.Where(x => x.Username == "Benjamin")); + uselect = (User)database.UserList.Where(x => x.Username == "Benjamin"); uselect.CreateTag("Tag 4", "#FF0000"); // add some default logos and themes - database.GetDefaultLogoList().Add(new Logo("Logo_1", "logo")); - database.GetDefaultLogoList().Add(new Logo("Logo_2", "logo")); - database.GetDefaultLogoList().Add(new Logo("Logo_3", "logo")); + database.DefaultLogoList.Add(new Logo("Logo_1", "logo")); + database.DefaultLogoList.Add(new Logo("Logo_2", "logo")); + database.DefaultLogoList.Add(new Logo("Logo_3", "logo")); List colorListHexaCode = new("FF0000,00FF00,0000FF".Split(',')); database.AddTheme(new Theme("Theme_1", colorListHexaCode)); colorListHexaCode = new("FF00FF,00FFFF,FFFF00".Split(',')); @@ -61,9 +61,9 @@ namespace Notus_Persistance colorListHexaCode = new("000000,FFFFFF,000000".Split(',')); database.AddTheme(new Theme("Theme_3", colorListHexaCode)); - foreach (User user in database.GetUserList()) + foreach (User user in database.UserList) { - user.SetPassword(user.GetPassword().GetHashCode().ToString()); + user.ChangePassword(/*to add correctly hash code */); } return database; diff --git a/notus/Notus_Persistence/ToJSON.cs b/notus/Notus_Persistence/ToJSON.cs index d38cf11..070ef0b 100644 --- a/notus/Notus_Persistence/ToJSON.cs +++ b/notus/Notus_Persistence/ToJSON.cs @@ -20,7 +20,7 @@ namespace Notus_Persistance private const string DefaultLogoPath = ""; private static readonly DataContractJsonSerializer DatabasejsonSerializer = new(typeof(Database)); - public void SaveDatabaseData(List UserList, Dictionary> AddedThemeFromUser) + public void SaveDatabaseData(List UserList) { using (FileStream fileStream = File.Create(DatabaseDataFilePath)) { @@ -31,7 +31,6 @@ namespace Notus_Persistance true))//<- this boolean says that we sant indentation { DatabasejsonSerializer.WriteObject(writer, UserList); - DatabasejsonSerializer.WriteObject(writer, AddedThemeFromUser); } } }