diff --git a/notus/Biblioteque_de_Class/Database.cs b/notus/Biblioteque_de_Class/Database.cs index 2013dce..54879de 100644 --- a/notus/Biblioteque_de_Class/Database.cs +++ b/notus/Biblioteque_de_Class/Database.cs @@ -78,7 +78,7 @@ namespace Biblioteque_de_Class return user; } } - throw new AlreadyUsedException("No user found with this username."); + throw new NotFoundException("No user found with this username."); } /// @@ -112,12 +112,16 @@ namespace Biblioteque_de_Class { throw new AlreadyUsedException("Username already used."); } - else if (existingUser.Email == user.Email) + else if (user.Email != "") { - throw new AlreadyUsedException("Email already used."); + if (existingUser.Email == user.Email) + { + throw new AlreadyUsedException("Email already used."); + } } } UserList.Add(user); + user.CreateNote("", ""); // création d'une note vide pour l'utilisateur } /// diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index 02f205b..cbbdad6 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -1,14 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.ComponentModel; +using System.Drawing; using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace Biblioteque_de_Class { [DataContract(IsReference = true)] - public class Note + public class Note : INotifyPropertyChanged { [DataMember] public int id { get; init; } @@ -18,11 +15,17 @@ namespace Biblioteque_de_Class public string Name { get { return name; } - set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } + set { if (value == "") { name = "Unnamed Note"; } else { name = value; } OnPropertyChanged(nameof(Name)); } } [DataMember] - public string Text { get; private set; } = ""; + private string text; + public string Text { + get => text; + set { + text = value; + OnPropertyChanged(nameof(Text)); + } } [DataMember] private string logoPath; @@ -30,7 +33,7 @@ namespace Biblioteque_de_Class public string LogoPath { get { return logoPath; } - private set { if (value == null) { logoPath = "PATH TO DEFAULT LOGO"; } else { logoPath = value; } } + private set { if (value == "") { logoPath = "PATH TO DEFAULT LOGO"; } else { logoPath = value; } OnPropertyChanged(nameof(LogoPath)); } } [DataMember] @@ -45,7 +48,23 @@ namespace Biblioteque_de_Class public List Editors { get; private set; } [DataMember] public User Owner { get; private set; } + public bool isfavorite; + public bool IsFavorite + { + get => isfavorite; + set + { + isfavorite = value; + OnPropertyChanged(nameof(IsFavorite)); + } + } + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } public Note(int initId,string name, string logoPath, User owner) { id = initId; diff --git a/notus/Biblioteque_de_Class/Tags.cs b/notus/Biblioteque_de_Class/Tags.cs index f5d046b..6ac1f1d 100644 --- a/notus/Biblioteque_de_Class/Tags.cs +++ b/notus/Biblioteque_de_Class/Tags.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; using System.Linq; using System.Runtime.Serialization; using System.Text; @@ -11,10 +13,40 @@ namespace Biblioteque_de_Class public class Tags { [DataMember] - public string Name { get; set; } + private string name; + public string Name + { + get { return name; } + set + { + if (name != value) + { + name = value; + OnPropertyChanged(nameof(Name)); + } + } + } [DataMember] - public string Color { get; set; } - + private string color; + public string Color + { + get { return color; } + set + { + if (color != value) + { + color = value; + OnPropertyChanged(nameof(Color)); + } + } + } + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + public Tags(string name, string color) { Name = name; diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs index dad2a6c..e5b4afd 100644 --- a/notus/Biblioteque_de_Class/User.cs +++ b/notus/Biblioteque_de_Class/User.cs @@ -6,29 +6,158 @@ using System.Runtime.Serialization; namespace Biblioteque_de_Class { [DataContract] - public class User + public class User : INotifyPropertyChanged { + public event PropertyChangedEventHandler PropertyChanged; + + void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + [DataMember] - public string Username { get; set; } + private string username; + public string Username + { + get { return username; } + set + { + if (username == value) + return; + username = value; + OnPropertyChanged(nameof(Username)); + } + } [DataMember] - public string Email { get; private set; } + private string email; + public string Email + { + get { return email; } + set + { + if (email == value) + return; + email = value; + OnPropertyChanged(nameof(Email)); + } + } [DataMember] - public string Password { get; private set; } + private string password; + public string Password + { + get { return password; } + set + { + if (password == value) + return; + password = value; + OnPropertyChanged(nameof(Password)); + } + } [DataMember] - public string Picture { get; private set; } + private string picture; + public string Picture + { + get { return picture; } + set + { + if (picture == value) + return; + picture = value; + OnPropertyChanged(nameof(Picture)); + } + } [DataMember] - public Theme UseTheme { get; set; } + private Theme useTheme; + public Theme UseTheme + { + get { return useTheme; } + set + { + if (useTheme == value) + return; + useTheme = value; + OnPropertyChanged(nameof(UseTheme)); + } + } [DataMember] - public List NoteList { get; set; } + private List noteList; + public List NoteList + { + get { return noteList; } + set + { + if (noteList == value) + return; + noteList = value; + OnPropertyChanged(nameof(NoteList)); + } + } [DataMember] - public List TagList { get; private set; } + private List tagList; + public List TagList + { + get { return tagList; } + set + { + if (tagList == value) + return; + tagList = value; + OnPropertyChanged(nameof(TagList)); + } + } [DataMember] - public List FavList { get; private set; } + private List favList; + public List FavList + { + get { return favList; } + set + { + if (favList == value) + return; + favList = value; + OnPropertyChanged(nameof(FavList)); + } + } [DataMember(EmitDefaultValue = false)] - public bool IsConnected { get; set; } + private bool isConnected; + public bool IsConnected + { + get { return isConnected; } + set + { + if (isConnected == value) + return; + isConnected = value; + OnPropertyChanged(nameof(IsConnected)); + } + } + [DataMember] + private Dictionary> noteTagged; + public Dictionary> NoteTagged + { + get { return noteTagged; } + set + { + if (noteTagged == value) + return; + noteTagged = value; + OnPropertyChanged(nameof(NoteTagged)); + } + } [DataMember] - public Dictionary> NoteTagged { get; set; } - public List AddedTheme { get; set; } + private List addedTheme; + public List AddedTheme + { + get { return addedTheme; } + set + { + if (addedTheme == value) + return; + addedTheme = value; + OnPropertyChanged(nameof(AddedTheme)); + } + } public User(string username, string email, string password) { @@ -161,6 +290,7 @@ namespace Biblioteque_de_Class throw new AlreadyExistException("Note already in favorites"); } FavList.Add(note); + note.IsFavorite = true; } /// @@ -171,6 +301,7 @@ namespace Biblioteque_de_Class if (FavList.Contains(note)) { FavList.Remove(note); + note.IsFavorite = false; } else { @@ -183,11 +314,14 @@ namespace Biblioteque_de_Class /// public Note CreateNote(string name, string imagePath) { - foreach (Note existingNote in NoteList) + if (name != "") { - if (existingNote.Name == name) + foreach (Note existingNote in NoteList) { - throw new AlreadyExistException("Note already exists"); + if (existingNote.Name == name) + { + throw new AlreadyExistException("Note already exists"); + } } } Note note; diff --git a/notus/Tests/UnitTests_Model/Database_Tests.cs b/notus/Tests/UnitTests_Model/Database_Tests.cs index 1698b23..cc71f7f 100644 --- a/notus/Tests/UnitTests_Model/Database_Tests.cs +++ b/notus/Tests/UnitTests_Model/Database_Tests.cs @@ -63,7 +63,7 @@ namespace UnitTests_Model public void GetUser_UserDoesNotExist_ThrowsException() { string userName = "Eve"; - Assert.Throws(() => database.GetUser(userName)); + Assert.Throws(() => database.GetUser(userName)); } // ComparePassword tests diff --git a/notus/notus_vue/App.xaml b/notus/notus_vue/App.xaml index 0c897b2..3c0d4d9 100644 --- a/notus/notus_vue/App.xaml +++ b/notus/notus_vue/App.xaml @@ -1,6 +1,8 @@  @@ -11,4 +13,5 @@ + diff --git a/notus/notus_vue/App.xaml.cs b/notus/notus_vue/App.xaml.cs index f6bc467..11b7f9f 100644 --- a/notus/notus_vue/App.xaml.cs +++ b/notus/notus_vue/App.xaml.cs @@ -6,15 +6,54 @@ namespace notus; public partial class App : Application { - public PersistenceManager manager = new PersistenceManager(new Stub()); - public Database db = new Database(); + public PersistenceManager Mgr { get; private set; } = new PersistenceManager(new Stub()); + public Database db = new Database(); public App() { InitializeComponent(); - db = manager.LoadDatabaseData(); + db = Mgr.LoadDatabaseData(); + BindingContext = db; MainPage = new AppShell(); - } - - + } + protected override Window CreateWindow(IActivationState activationState) + { + Window window = base.CreateWindow(activationState); + + // Set minimum height and width + window.MinimumHeight = 670; + window.MinimumWidth = 1200; + + return window; + } + + private User selecUser; + public User SelectedUser + { + get + { + return selecUser; + } + set + { + selecUser = value; + OnPropertyChanged(nameof(SelectedUser)); + } + } + + private Note selecNote; + public Note SelectedNote + { + get + { + return selecNote; + } + set + { + selecNote = value; + OnPropertyChanged(nameof(SelectedNote)); + } + } + + } diff --git a/notus/notus_vue/AppShell.xaml b/notus/notus_vue/AppShell.xaml index 15947ae..e627a86 100644 --- a/notus/notus_vue/AppShell.xaml +++ b/notus/notus_vue/AppShell.xaml @@ -3,12 +3,14 @@ x:Class="notus.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:model="clr-namespace:Biblioteque_de_Class;assembly=Biblioteque_de_Class" + xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:notus" Shell.FlyoutBehavior="Locked" Shell.FlyoutWidth="30" - Shell.NavBarIsVisible="True" + Shell.NavBarIsVisible="False" Shell.BackgroundColor="Grey"> - + - + + + - + - + - + @@ -27,6 +31,21 @@ + +