debut huge upgrade

pull/15/head
Matheo THIERRY 2 years ago
parent ff86a3943d
commit 67245868b2

@ -14,27 +14,19 @@ namespace Biblioteque_de_Class
public class Database public class Database
{ {
[DataMember] [DataMember]
private List<Logo> DefaultLogoList; public List<Logo> DefaultLogoList { get; private set; }
[DataMember] [DataMember]
private List<Theme> ThemeList; public List<Theme> ThemeList { get; private set; }
[DataMember] [DataMember]
private List<User> UserList; public List<User> UserList { get; private set; }
[DataMember]
private Dictionary<User, List<Theme>> AddedThemeList;
public Database() public Database()
{ {
DefaultLogoList = new List<Logo>(); DefaultLogoList = new List<Logo>();
ThemeList = new List<Theme>(); ThemeList = new List<Theme>();
UserList = new List<User>(); UserList = new List<User>();
AddedThemeList = new Dictionary<User, List<Theme>>();
} }
public List<Logo> GetDefaultLogoList() { return DefaultLogoList; }
public List<Theme> GetThemeList() { return ThemeList; }
public List<User> GetUserList() { return UserList; }
public Dictionary<User,List<Theme>> GetAddedThemeFromUser() { return AddedThemeList; }
public void SetDefaultLogoList(List<Logo> defaultLogoList) { DefaultLogoList = defaultLogoList; } public void SetDefaultLogoList(List<Logo> defaultLogoList) { DefaultLogoList = defaultLogoList; }
public void SetDefaultThemeList(List<Theme> defaultThemeList) { ThemeList = defaultThemeList; } public void SetDefaultThemeList(List<Theme> defaultThemeList) { ThemeList = defaultThemeList; }
@ -45,7 +37,7 @@ namespace Biblioteque_de_Class
{ {
List<User> searchedUsers = new List<User>(); List<User> searchedUsers = new List<User>();
string search = name.ToLower(); 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; return searchedUsers;
} }
@ -56,7 +48,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Logo logo in DefaultLogoList) 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."); throw new NotFoundException("No logo link found.");
} }
@ -68,7 +60,7 @@ namespace Biblioteque_de_Class
{ {
foreach (User user in UserList) foreach (User user in UserList)
{ {
if (user.GetUsername() == name) if (user.Username == name)
{ {
return user; return user;
} }
@ -79,7 +71,7 @@ namespace Biblioteque_de_Class
/// <summary> /// <summary>
/// comparer le mot de passe entré avec celui de l'utilisateur /// comparer le mot de passe entré avec celui de l'utilisateur
/// </summary> /// </summary>
public static bool ComparePassword(User user, string? password) => user.GetPassword() == password; public static bool ComparePassword(User user, string? password) => user.Password == password;
/// <summary> /// <summary>
/// rechercher un mail dans la liste d'utilisateur /// rechercher un mail dans la liste d'utilisateur
@ -88,7 +80,7 @@ namespace Biblioteque_de_Class
{ {
foreach (User user in UserList) foreach (User user in UserList)
{ {
if (string.Equals(user.GetEmail(), email)) if (string.Equals(user.Email, email))
{ {
return true; return true;
} }
@ -103,11 +95,11 @@ namespace Biblioteque_de_Class
{ {
foreach (User existingUser in UserList) foreach (User existingUser in UserList)
{ {
if (existingUser.GetUsername() == user.GetUsername()) if (existingUser.Username == user.Username)
{ {
throw new AlreadyUsedException("Username already used."); throw new AlreadyUsedException("Username already used.");
} }
else if (existingUser.GetEmail() == user.GetEmail()) else if (existingUser.Email == user.Email)
{ {
throw new AlreadyUsedException("Email already used."); throw new AlreadyUsedException("Email already used.");
} }
@ -137,7 +129,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Theme existingTheme in ThemeList) foreach (Theme existingTheme in ThemeList)
{ {
if (existingTheme.GetName() == theme.GetName()) if (existingTheme.Name == theme.Name)
{ {
throw new AlreadyUsedException("Theme already used."); throw new AlreadyUsedException("Theme already used.");
} }
@ -152,7 +144,7 @@ namespace Biblioteque_de_Class
{ {
if (ThemeList.Contains(theme)) 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."); throw new AlreadyUsedException("This theme is used a default theme.");
} }
@ -171,7 +163,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Theme theme in ThemeList) foreach (Theme theme in ThemeList)
{ {
if (theme.GetName() == name) if (theme.Name == name)
{ {
return theme; return theme;
} }
@ -186,9 +178,9 @@ namespace Biblioteque_de_Class
{ {
foreach (Theme existingTheme in ThemeList) foreach (Theme existingTheme in ThemeList)
{ {
if (existingTheme.GetName() == theme.GetName()) if (existingTheme.Name == theme.Name)
{ {
existingTheme.SetName(newName); existingTheme.Name = newName;
return; return;
} }
} }
@ -202,20 +194,27 @@ namespace Biblioteque_de_Class
{ {
foreach (Theme existingTheme in ThemeList) foreach (Theme existingTheme in ThemeList)
{ {
if (existingTheme.GetName() == theme.GetName()) if (existingTheme.Name == theme.Name)
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
existingTheme.ChangeColor(existingTheme.GetColor(i), newColorList[i]); existingTheme.ChangeColor(existingTheme.ColorList[i], newColorList[i]);
} }
return; return;
} }
} }
} }
public List<Theme> 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;
} }
} }
} }

@ -48,9 +48,6 @@ namespace Biblioteque_de_Class
} }
} }
[Serializable] [Serializable]
public class FileException : Exception public class FileException : Exception
{ {

@ -8,10 +8,8 @@ namespace Biblioteque_de_Class
{ {
public interface IManager public interface IManager
{ {
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser); public void SaveDatabaseData(List<User> UserList);
public Database LoadDatabaseData(); public Database LoadDatabaseData();
public List<Theme> LoadDefaultTheme(); public List<Theme> LoadDefaultTheme();
public List<Logo> LoadDefaultLogo(); public List<Logo> LoadDefaultLogo();
} }

@ -8,8 +8,8 @@ namespace Biblioteque_de_Class
{ {
public class Logo public class Logo
{ {
private string Name { get; set; } public string Name { get; set; }
private string LogoLink { get; set; } public string LogoLink { get; set; }
public Logo(string name, string logoLink) public Logo(string name, string logoLink)
{ {
@ -17,12 +17,6 @@ namespace Biblioteque_de_Class
LogoLink = logoLink; 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}"; public override string ToString() => $"Logo -> Name: {Name}\nLink: {LogoLink}";
} }
} }

@ -16,11 +16,11 @@ namespace Biblioteque_de_Class
public string Name public string Name
{ {
get { return 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] [DataMember]
private string Text { get; set; } = ""; public string Text { get; private set; } = "";
[DataMember] [DataMember]
private string logoPath; private string logoPath;
@ -32,17 +32,17 @@ namespace Biblioteque_de_Class
} }
[DataMember] [DataMember]
private DateOnly CreationDate { get; } public DateOnly CreationDate { get; init; }
[DataMember] [DataMember]
private DateOnly ModificationDate { get; set; } public DateOnly ModificationDate { get; private set; }
[DataMember] [DataMember]
private readonly List<NoteImage> ImageList; public List<NoteImage> ImageList { get; private set; }
[DataMember] [DataMember]
private readonly List<User> Collaborators; public List<User> Collaborators { get; private set; }
[DataMember] [DataMember]
private readonly List<User> Editors; public List<User> Editors { get; private set; }
[DataMember] [DataMember]
private readonly User Owner; public User Owner { get; private set; }
public Note(string name, string logoPath, User owner) public Note(string name, string logoPath, User owner)
{ {
@ -56,22 +56,8 @@ namespace Biblioteque_de_Class
Owner = owner; 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<NoteImage> GetImageList() { return ImageList; }
public List<User> GetCollaborators() { return Collaborators; }
public List<User> GetEditors() { return Editors; }
public User GetOwner() { return Owner; }
public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}"; 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); }
/// <summary> /// <summary>
/// vérifier si l'utilisateur est le propriétaire de la note /// vérifier si l'utilisateur est le propriétaire de la note
/// </summary> /// </summary>
@ -90,7 +76,7 @@ namespace Biblioteque_de_Class
{ {
foreach (NoteImage image in ImageList) foreach (NoteImage image in ImageList)
{ {
if (image.GetName() == name) if (image.Name == name)
{ {
ImageList.Remove(image); ImageList.Remove(image);
return; return;
@ -119,7 +105,7 @@ namespace Biblioteque_de_Class
{ {
if (VerifyOwner(owner)) { Collaborators.Add(user); } if (VerifyOwner(owner)) { Collaborators.Add(user); }
else { throw new NotAllowedException("User is not the owner"); } else { throw new NotAllowedException("User is not the owner"); }
user.GetNoteList().Add(this); user.NoteList.Add(this);
} }
/// <summary> /// <summary>
@ -129,7 +115,7 @@ namespace Biblioteque_de_Class
{ {
if (VerifyOwner(owner)) { Collaborators.Remove(user); } if (VerifyOwner(owner)) { Collaborators.Remove(user); }
else { throw new NotAllowedException("User is not the owner"); } else { throw new NotAllowedException("User is not the owner"); }
user.GetNoteList().Remove(this); user.NoteList.Remove(this);
} }
/// <summary> /// <summary>

@ -8,9 +8,9 @@ namespace Biblioteque_de_Class
{ {
public class NoteImage public class NoteImage
{ {
private int Name { get; set; } public int Name { get; set; }
private string ImageLink { get; set; } public string ImageLink { get; set; }
private string Position { get; set; } public string Position { get; set; }
public NoteImage(int name, string imageLink, string position) public NoteImage(int name, string imageLink, string position)
{ {
@ -19,14 +19,6 @@ namespace Biblioteque_de_Class
Position = position; 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}"; public override string ToString() => $"image -> name: {Name}\nlink: {ImageLink}";
} }
} }

@ -15,7 +15,7 @@ namespace Biblioteque_de_Class
public void SaveDatabaseData(Database database) public void SaveDatabaseData(Database database)
{ {
persistence.SaveDatabaseData(database.GetUserList(), database.GetAddedThemeFromUser()); persistence.SaveDatabaseData(database.UserList);
} }
public Database LoadDatabaseData() public Database LoadDatabaseData()

@ -8,8 +8,8 @@ namespace Biblioteque_de_Class
{ {
public class Tags public class Tags
{ {
private string Name { get; set; } public string Name { get; set; }
private string Color { get; set; } public string Color { get; set; }
public Tags(string name, string color) public Tags(string name, string color)
{ {
@ -17,11 +17,6 @@ namespace Biblioteque_de_Class
Color = color; 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}"; public override string ToString() => $"tag -> name: {Name}\ncolor: {Color}";
} }
} }

@ -8,8 +8,8 @@ namespace Biblioteque_de_Class
{ {
public class Theme public class Theme
{ {
private string Name { get; set; } public string Name { get; set; }
private readonly List<string> ColorList; public List<string> ColorList { get; private set; }
public Theme(string name, List<string> colorList) public Theme(string name, List<string> colorList)
{ {
@ -17,11 +17,6 @@ namespace Biblioteque_de_Class
ColorList = colorList; ColorList = colorList;
} }
public string GetName() { return Name; }
public void SetName(string name) { Name = name; }
public List<string> 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"; public override string ToString() => $"name: {Name}\ncolor 1: {ColorList[0]}\ncolor 2: {ColorList[1]}\ncolor 3: {ColorList[2]}\n";
/// <summary> /// <summary>

@ -9,25 +9,26 @@ namespace Biblioteque_de_Class
public class User public class User
{ {
[DataMember] [DataMember]
private string Username { get; set; } public string Username { get; set; }
[DataMember] [DataMember]
private string Email { get; set; } public string Email { get; private set; }
[DataMember] [DataMember]
private string Password { get; set; } public string Password { get; private set; }
[DataMember] [DataMember]
private string Picture { get; set; } public string Picture { get; private set; }
[DataMember] [DataMember]
private Theme Theme; public Theme UseTheme { get; set; }
[DataMember] [DataMember]
private List<Note> NoteList; public List<Note> NoteList { get; set; }
[DataMember] [DataMember]
private List<Tags> TagList; public List<Tags> TagList { get; private set; }
[DataMember] [DataMember]
private List<Note> FavList; public List<Note> FavList { get; private set; }
[DataMember(EmitDefaultValue = false)] [DataMember(EmitDefaultValue = false)]
private bool IsConnected { get; set; } public bool IsConnected { get; set; }
[DataMember] [DataMember]
private Dictionary<Note, List<Tags>> NoteTagged; public Dictionary<Note, List<Tags>> NoteTagged { get; set; }
public List<Theme> AddedTheme { get; set; }
public User(string username, string email, string password) public User(string username, string email, string password)
{ {
@ -41,25 +42,6 @@ namespace Biblioteque_de_Class
NoteTagged = new Dictionary<Note, List<Tags>>(); NoteTagged = new Dictionary<Note, List<Tags>>();
} }
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<Note> GetNoteList() { return NoteList; }
public List<Tags> GetTagList() { return TagList; }
public List<Note> GetFavList() { return FavList; }
public bool GetIsConnected() { return IsConnected; }
public Dictionary<Note, List<Tags>> GetNoteTagged() { return NoteTagged; }
public List<Tags> 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}"; public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}";
/// <summary> /// <summary>
@ -71,7 +53,7 @@ namespace Biblioteque_de_Class
string search = name.ToLower(); string search = name.ToLower();
foreach (Note note in ToResearchIntoList) foreach (Note note in ToResearchIntoList)
{ {
if (note.GetName().ToLower().Contains(search)) if (note.Name.ToLower().Contains(search))
{ {
searchedNotes.Add(note); searchedNotes.Add(note);
} }
@ -88,7 +70,7 @@ namespace Biblioteque_de_Class
string search = name.ToLower(); string search = name.ToLower();
foreach (Tags tag in ToResearchIntoList) foreach (Tags tag in ToResearchIntoList)
{ {
if (tag.GetName().ToLower().Contains(search)) if (tag.Name.ToLower().Contains(search))
{ {
searchedTags.Add(tag); searchedTags.Add(tag);
} }
@ -102,7 +84,7 @@ namespace Biblioteque_de_Class
string search = name.ToLower(); string search = name.ToLower();
foreach (Note note in ToResearchIntoList) 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); searchedNotes.Add(note);
} }
@ -114,7 +96,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Note note in NoteList) foreach (Note note in NoteList)
{ {
if (note.GetName() == name) if (note.Name == name)
{ {
return note; return note;
} }
@ -126,7 +108,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Tags tag in TagList) foreach (Tags tag in TagList)
{ {
if (tag.GetName() == name) if (tag.Name == name)
{ {
return tag; return tag;
} }
@ -168,7 +150,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Note existingNote in NoteList) foreach (Note existingNote in NoteList)
{ {
if (existingNote.GetName() == name) if (existingNote.Name == name)
{ {
throw new AlreadyExistException("Note already exists"); throw new AlreadyExistException("Note already exists");
} }
@ -185,7 +167,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Note existingNote in NoteList) foreach (Note existingNote in NoteList)
{ {
if (existingNote.GetName() == note) if (existingNote.Name == note)
{ {
NoteList.Remove(existingNote); NoteList.Remove(existingNote);
NoteTagged.Remove(existingNote); NoteTagged.Remove(existingNote);
@ -202,7 +184,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Tags tag in TagList) foreach (Tags tag in TagList)
{ {
if (tag.GetName() == name) if (tag.Name == name)
{ {
throw new AlreadyExistException("Tag already exists"); throw new AlreadyExistException("Tag already exists");
} }
@ -217,7 +199,7 @@ namespace Biblioteque_de_Class
{ {
foreach (Tags tag in TagList) foreach (Tags tag in TagList)
{ {
if (tag.GetName() == name) if (tag.Name == name)
{ {
TagList.Remove(tag); TagList.Remove(tag);
return; return;
@ -273,5 +255,32 @@ namespace Biblioteque_de_Class
NoteTagged.Remove(note); 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;
}
} }
} }

@ -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 // déclaration d'un user qui sera utiliser pour servir de personne connecté dans l'app
User u = new("", "", ""); User u = new("", "", "");
User uvide = new("", "", ""); User uvide = new("", "", "") { IsConnected = false };
uvide.SetIsConnected(false);
// déclaration d'une note qui sera utiliser pour servir de note selectionnée // déclaration d'une note qui sera utiliser pour servir de note selectionnée
Note n = new("","",uvide); Note n = new("","",uvide);
@ -65,25 +64,25 @@ bool choix_note()
void displayNote() 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() 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() 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())) if (Database.ComparePassword(u, password.GetHashCode().ToString()))
{ {
u.SetIsConnected(true); u.IsConnected = true;
Console.WriteLine("\nConnection réussie !\n"); Console.WriteLine("\nConnection réussie !\n");
menu = false; menu = false;
} }
@ -215,7 +214,7 @@ while (menu)
{ {
u = new User(nom, "", password.GetHashCode().ToString()); u = new User(nom, "", password.GetHashCode().ToString());
db.AddUser(u); db.AddUser(u);
db.GetUser(nom).SetIsConnected(true); db.GetUser(nom).IsConnected = true;
Console.WriteLine("\nConnection réussie !\n"); Console.WriteLine("\nConnection réussie !\n");
menu = false; menu = false;
break; break;
@ -226,7 +225,7 @@ while (menu)
} }
} }
//une fois connecté ou inscription fait //une fois connecté ou inscription fait
while (u.GetIsConnected()) while (u.IsConnected)
{ {
Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
@ -245,7 +244,7 @@ while (u.GetIsConnected())
switch (Console.ReadLine()) switch (Console.ReadLine())
{ {
case "1": case "1":
researchlist = u.GetNoteList(); researchlist = u.NoteList;
Console.WriteLine("\nEntrez la note que vous cherchez. "); Console.WriteLine("\nEntrez la note que vous cherchez. ");
string? wantedSearchNote = Console.ReadLine(); string? wantedSearchNote = Console.ReadLine();
Console.WriteLine("\nChercher par tags ? (o/N) "); Console.WriteLine("\nChercher par tags ? (o/N) ");
@ -263,7 +262,7 @@ while (u.GetIsConnected())
break; break;
case "5": case "5":
Console.WriteLine("\ndéconnecté! \n"); Console.WriteLine("\ndéconnecté! \n");
u.SetIsConnected(false); u.IsConnected = false;
u = uvide; u = uvide;
break; break;
default: default:
@ -288,7 +287,7 @@ while (u.GetIsConnected())
Console.WriteLine("| 7/ - retour - |"); Console.WriteLine("| 7/ - retour - |");
Console.WriteLine("| |"); Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|\n"); Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("note actuelle : " + n.GetName()); Console.WriteLine("note actuelle : " + n.Name);
Console.WriteLine("rentrez votre choix."); Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine()) switch (Console.ReadLine())
{ {
@ -297,19 +296,19 @@ while (u.GetIsConnected())
break; break;
case "2": case "2":
if (!choix_note()) { break; } if (!choix_note()) { break; }
Console.WriteLine("\n" + n.GetName() + " :"); Console.WriteLine("\n" + n.Name + " :");
Console.WriteLine(n.GetText()); Console.WriteLine(n.Text);
break; break;
case "3": case "3":
if (!choix_note()) { break;} if (!choix_note()) { break;}
Console.WriteLine("\nChoisissez le nouveau nom de la note (entrer - nom par defaut)"); Console.WriteLine("\nChoisissez le nouveau nom de la note (entrer - nom par defaut)");
string? wantedNewNameNote = Console.ReadLine(); string? wantedNewNameNote = Console.ReadLine();
wantedNewNameNote??= ""; wantedNewNameNote??= "";
n.SetName(wantedNewNameNote); u.SetNoteName(n, wantedNewNameNote);
break; break;
case "4": case "4":
if (!choix_note()) { break; } if (!choix_note()) { break; }
Console.WriteLine(n.GetText()); Console.WriteLine(n.Text);
Console.WriteLine("\nEntrez le texte à ajouter"); Console.WriteLine("\nEntrez le texte à ajouter");
string? wantedTextNote = Console.ReadLine(); string? wantedTextNote = Console.ReadLine();
wantedTextNote??= ""; wantedTextNote??= "";
@ -360,7 +359,7 @@ while (u.GetIsConnected())
case "1": case "1":
Console.WriteLine("\nChoisissez le nom du tag."); Console.WriteLine("\nChoisissez le nom du tag.");
string? wantedNameTag = Console.ReadLine(); string? wantedNameTag = Console.ReadLine();
wantedNameTag??= "NoName" + u.GetTagList().Count.ToString(); wantedNameTag??= "NoName" + u.NoteList.Count.ToString();
Console.WriteLine("\nChoisissez la couleur du tag."); Console.WriteLine("\nChoisissez la couleur du tag.");
string? wantedColorTag = Console.ReadLine(); string? wantedColorTag = Console.ReadLine();
wantedColorTag??= "#000000"; wantedColorTag??= "#000000";
@ -428,9 +427,9 @@ while (u.GetIsConnected())
try{ try{
wantedRemoveNote = u.GetNoteByName(wantedRemoveNameNote); wantedRemoveNote = u.GetNoteByName(wantedRemoveNameNote);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;} }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."); Console.WriteLine("\nChoisissez le nom du tag à supprimer.");
string? wantedRemoveNameTag = Console.ReadLine(); string? wantedRemoveNameTag = Console.ReadLine();
@ -516,7 +515,7 @@ while (u.GetIsConnected())
Console.WriteLine("\nChoisissez le nouveau pseudo."); Console.WriteLine("\nChoisissez le nouveau pseudo.");
string? wantedNewPseudo = Console.ReadLine(); string? wantedNewPseudo = Console.ReadLine();
if(wantedNewPseudo == null){break;} if(wantedNewPseudo == null){break;}
u.SetUsername(wantedNewPseudo); db.ChangeUsername(u,wantedNewPseudo);
break; break;
case "2": case "2":
Console.WriteLine("\nChoisissez le nouveau mot de passe."); 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"); Console.WriteLine("\nLe mot de passe doit contenir au moins 8 caractères.\n");
break; 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"); Console.WriteLine("\nLe nouveau mot de passe doit être différent de l'ancien.\n");
break; break;
} }
u.SetPassword(wantedNewPassword); u.ChangePassword(wantedNewPassword);
break; break;
case "3": case "3":
paraCompte = false; paraCompte = false;
@ -568,7 +567,7 @@ while (u.GetIsConnected())
{ {
twantedTheme = db.GetTheme(wantedTheme); twantedTheme = db.GetTheme(wantedTheme);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;} }catch (Exception ex) { Console.WriteLine(ex.Message); break;}
u.SetTheme(twantedTheme); u.ChangeTheme(twantedTheme);
break; break;
case "2": case "2":
List<string>? themeList; List<string>? themeList;

@ -12,7 +12,7 @@ namespace Notus_Persistance
{ {
public class Stub : IManager public class Stub : IManager
{ {
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser) public void SaveDatabaseData(List<User> UserList)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -31,7 +31,7 @@ namespace Notus_Persistance
database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois")); database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois"));
// add some notes and tags to go faster // 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 1", "");
user.CreateNote("Note 2", ""); user.CreateNote("Note 2", "");
@ -41,19 +41,19 @@ namespace Notus_Persistance
} }
// add note to user for sharing note test mixed with tag // 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.CreateNote("Note 4", "Logo_1");
uselect.CreateTag("Tag 3", "#00FF00"); uselect.CreateTag("Tag 3", "#00FF00");
nselect = (Note)uselect.GetNoteList().Where(x => x.GetName() == "Note 4"); nselect = (Note)uselect.NoteList.Where(x => x.Name == "Note 4");
uselect.AddTagToNoteList(nselect, (Tags)uselect.GetTagList().Where(x => x.GetName() == "Tag 3")); uselect.AddTagToNoteList(nselect, (Tags)uselect.TagList.Where(x => x.Name == "Tag 3"));
nselect.AddCollaborator(uselect,(User)database.GetUserList().Where(x => x.GetUsername() == "Benjamin")); nselect.AddCollaborator(uselect,(User)database.UserList.Where(x => x.Username == "Benjamin"));
uselect = (User)database.GetUserList().Where(x => x.GetUsername() == "Benjamin"); uselect = (User)database.UserList.Where(x => x.Username == "Benjamin");
uselect.CreateTag("Tag 4", "#FF0000"); uselect.CreateTag("Tag 4", "#FF0000");
// add some default logos and themes // add some default logos and themes
database.GetDefaultLogoList().Add(new Logo("Logo_1", "logo")); database.DefaultLogoList.Add(new Logo("Logo_1", "logo"));
database.GetDefaultLogoList().Add(new Logo("Logo_2", "logo")); database.DefaultLogoList.Add(new Logo("Logo_2", "logo"));
database.GetDefaultLogoList().Add(new Logo("Logo_3", "logo")); database.DefaultLogoList.Add(new Logo("Logo_3", "logo"));
List<string> colorListHexaCode = new("FF0000,00FF00,0000FF".Split(',')); List<string> colorListHexaCode = new("FF0000,00FF00,0000FF".Split(','));
database.AddTheme(new Theme("Theme_1", colorListHexaCode)); database.AddTheme(new Theme("Theme_1", colorListHexaCode));
colorListHexaCode = new("FF00FF,00FFFF,FFFF00".Split(',')); colorListHexaCode = new("FF00FF,00FFFF,FFFF00".Split(','));
@ -61,9 +61,9 @@ namespace Notus_Persistance
colorListHexaCode = new("000000,FFFFFF,000000".Split(',')); colorListHexaCode = new("000000,FFFFFF,000000".Split(','));
database.AddTheme(new Theme("Theme_3", colorListHexaCode)); 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; return database;

@ -20,7 +20,7 @@ namespace Notus_Persistance
private const string DefaultLogoPath = ""; private const string DefaultLogoPath = "";
private static readonly DataContractJsonSerializer DatabasejsonSerializer = new(typeof(Database)); private static readonly DataContractJsonSerializer DatabasejsonSerializer = new(typeof(Database));
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser) public void SaveDatabaseData(List<User> UserList)
{ {
using (FileStream fileStream = File.Create(DatabaseDataFilePath)) using (FileStream fileStream = File.Create(DatabaseDataFilePath))
{ {
@ -31,7 +31,6 @@ namespace Notus_Persistance
true))//<- this boolean says that we sant indentation true))//<- this boolean says that we sant indentation
{ {
DatabasejsonSerializer.WriteObject(writer, UserList); DatabasejsonSerializer.WriteObject(writer, UserList);
DatabasejsonSerializer.WriteObject(writer, AddedThemeFromUser);
} }
} }
} }

Loading…
Cancel
Save