From 13e5cb95d89370c3663b88da80849aab7c11eace Mon Sep 17 00:00:00 2001 From: lobroda Date: Sun, 22 Oct 2023 09:47:39 +0100 Subject: [PATCH] ADD : base added - compiling but not working yet --- DtoAbstractLayer/DtoAbstractLayer.csproj | 5 + JsonReader/JsonReader.csproj | 2 + LibraryDTO/LibraryDTO.csproj | 5 + LivreLand/LivreLand.csproj | 4 +- LivreLand/View/EmpruntsPretsView.xaml | 4 +- LivreLand/View/FavorisView.xaml | 2 +- LivreLand/View/TousView.xaml | 2 +- LivreLand/ViewModel/ALirePlusTardVM.cs | 22 +- LivreLand/ViewModel/BibliothequeVM.cs | 46 +- LivreLand/ViewModel/ContactsVM.cs | 38 +- LivreLand/ViewModel/DetailsLivreVM.cs | 87 +-- LivreLand/ViewModel/EmpruntsPretsVM.cs | 127 +--- LivreLand/ViewModel/FavorisVM.cs | 17 +- LivreLand/ViewModel/FiltrageAuteurVM.cs | 20 +- LivreLand/ViewModel/FiltrageDateVM.cs | 20 +- LivreLand/ViewModel/FiltrageNoteVM.cs | 20 +- LivreLand/ViewModel/NavigatorVM.cs | 42 +- LivreLand/ViewModel/PopupISBNVM.cs | 20 +- LivreLand/ViewModel/ScanVM.cs | 104 +--- LivreLand/ViewModel/StatutLectureVM.cs | 22 +- LivreLand/ViewModel/TousVM.cs | 22 +- Model/Model.csproj | 5 + .../PersonalMVVMToolkit.csproj | 5 + Stub/Stub.csproj | 5 + StubbedDTO/StubbedDTO.csproj | 4 + Tests/Tests.csproj | 5 + Utils/Utils.csproj | 5 + ViewModels/AuthorVM.cs | 33 +- ViewModels/BookVM.cs | 87 +-- ViewModels/BorrowingVM.cs | 46 +- ViewModels/ContactVM.cs | 34 +- ViewModels/LoanVM.cs | 46 +- ViewModels/ManagerVM.cs | 555 +++++------------- ViewModels/PublishDateVM.cs | 17 +- ViewModels/RatingsVM.cs | 29 +- ViewModels/ViewModels.csproj | 6 +- 36 files changed, 554 insertions(+), 959 deletions(-) diff --git a/DtoAbstractLayer/DtoAbstractLayer.csproj b/DtoAbstractLayer/DtoAbstractLayer.csproj index 1e37083..db8e7a8 100644 --- a/DtoAbstractLayer/DtoAbstractLayer.csproj +++ b/DtoAbstractLayer/DtoAbstractLayer.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/JsonReader/JsonReader.csproj b/JsonReader/JsonReader.csproj index de1a611..0b45847 100644 --- a/JsonReader/JsonReader.csproj +++ b/JsonReader/JsonReader.csproj @@ -7,6 +7,8 @@ + + diff --git a/LibraryDTO/LibraryDTO.csproj b/LibraryDTO/LibraryDTO.csproj index cfadb03..d87a0e0 100644 --- a/LibraryDTO/LibraryDTO.csproj +++ b/LibraryDTO/LibraryDTO.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/LivreLand/LivreLand.csproj b/LivreLand/LivreLand.csproj index 8fac7be..fa50f85 100644 --- a/LivreLand/LivreLand.csproj +++ b/LivreLand/LivreLand.csproj @@ -54,13 +54,13 @@ - + + - diff --git a/LivreLand/View/EmpruntsPretsView.xaml b/LivreLand/View/EmpruntsPretsView.xaml index d1685d1..b293d4d 100644 --- a/LivreLand/View/EmpruntsPretsView.xaml +++ b/LivreLand/View/EmpruntsPretsView.xaml @@ -32,7 +32,7 @@ EmpruntsButtonCommand="{Binding EmpruntsPretsVM.EmpruntsButtonCommand}"/> - - - diff --git a/LivreLand/View/TousView.xaml b/LivreLand/View/TousView.xaml index f5e59e5..b0af1ef 100644 --- a/LivreLand/View/TousView.xaml +++ b/LivreLand/View/TousView.xaml @@ -165,7 +165,7 @@ Grid.Column="3"> - + diff --git a/LivreLand/ViewModel/ALirePlusTardVM.cs b/LivreLand/ViewModel/ALirePlusTardVM.cs index 2e3fb45..2410b2a 100644 --- a/LivreLand/ViewModel/ALirePlusTardVM.cs +++ b/LivreLand/ViewModel/ALirePlusTardVM.cs @@ -1,5 +1,6 @@ -using LivreLand.View; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using LivreLand.View; using System; using System.Collections.Generic; using System.Linq; @@ -10,15 +11,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class ALirePlusTardVM : BaseViewModel + [ObservableObject] + public partial class ALirePlusTardVM { - #region Properties + #region Fields - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private NavigatorVM navigator; - public ManagerVM Manager { get; private set; } + [ObservableProperty] + private ManagerVM manager; + + #endregion - public ICommand OnSelectionChangedCommand { get; private set; } + #region Properties #endregion @@ -28,13 +34,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - OnSelectionChangedCommand = new RelayCommand((bookVM) => OnSelectionChanged(bookVM)); } #endregion #region Methods + [RelayCommand] private void OnSelectionChanged(BookVM bookVM) { if (bookVM != null) diff --git a/LivreLand/ViewModel/BibliothequeVM.cs b/LivreLand/ViewModel/BibliothequeVM.cs index a8650fd..d410efd 100644 --- a/LivreLand/ViewModel/BibliothequeVM.cs +++ b/LivreLand/ViewModel/BibliothequeVM.cs @@ -1,4 +1,5 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; @@ -9,29 +10,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class BibliothequeVM : BaseViewModel + [ObservableObject] + public partial class BibliothequeVM { - #region Properties - - public NavigatorVM Navigator { get; private set; } - - public ManagerVM Manager { get; private set; } - - public ICommand AllBooksNavigateCommand { get; private set; } - - public ICommand AllLoansBorrowingsNavigateCommand { get; private set; } + #region Fields - public ICommand AllFavorisBooksNavigateCommand { get; private set; } + [ObservableProperty] + private NavigatorVM navigator; - public ICommand AllStatusBooksNavigateCommand { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ICommand AllToReadBooksNavigateCommand { get; private set; } - - public ICommand AllAuthorsNavigateCommand { get; private set; } - - public ICommand AllDatesNavigateCommand { get; private set; } + #endregion - public ICommand AllRatingsNavigateCommand { get; private set; } + #region Properties #endregion @@ -41,26 +33,20 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - AllBooksNavigateCommand = new RelayCommand(() => AllBooksNavigate()); - AllLoansBorrowingsNavigateCommand = new RelayCommand(() => AllLoansBorrowingsNavigate()); - AllFavorisBooksNavigateCommand = new RelayCommand(() => AllFavorisBooksNavigate()); - AllStatusBooksNavigateCommand = new RelayCommand(() => AllStatusBooksNavigate()); - AllToReadBooksNavigateCommand = new RelayCommand(() => AllToReadBooksNavigate()); - AllAuthorsNavigateCommand = new RelayCommand(() => AllAuthorsNavigate()); - AllDatesNavigateCommand = new RelayCommand(() => AllDatesNavigate()); - AllRatingsNavigateCommand = new RelayCommand(() => AllRatingsNavigate()); } #endregion #region Methods + [RelayCommand] private void AllBooksNavigate() { Manager.GetBooksFromCollectionCommand.Execute(null); Navigator.NavigationCommand.Execute("/tous"); } + [RelayCommand] private void AllLoansBorrowingsNavigate() { Manager.GetCurrentLoansCommand.Execute(null); @@ -68,36 +54,42 @@ namespace LivreLand.ViewModel Navigator.NavigationCommand.Execute("/pret"); } + [RelayCommand] private void AllFavorisBooksNavigate() { Manager.GetFavoriteBooksCommand.Execute(null); Navigator.NavigationCommand.Execute("/favoris"); } + [RelayCommand] private void AllStatusBooksNavigate() { Manager.GetBooksFromCollectionCommand.Execute(null); Navigator.NavigationCommand.Execute("/statut"); } + [RelayCommand] private void AllToReadBooksNavigate() { Manager.GetToBeReadBooksCommand.Execute(null); Navigator.NavigationCommand.Execute("/later"); } + [RelayCommand] private void AllAuthorsNavigate() { Manager.GetAllAuthorsCommand.Execute(null); Navigator.NavigationCommand.Execute("/auteur"); } + [RelayCommand] private void AllDatesNavigate() { Manager.GetAllPublishDatesCommand.Execute(null); Navigator.NavigationCommand.Execute("/date"); } + [RelayCommand] private void AllRatingsNavigate() { Manager.GetAllRatingsCommand.Execute(null); diff --git a/LivreLand/ViewModel/ContactsVM.cs b/LivreLand/ViewModel/ContactsVM.cs index 4d430be..7627e0b 100644 --- a/LivreLand/ViewModel/ContactsVM.cs +++ b/LivreLand/ViewModel/ContactsVM.cs @@ -1,5 +1,6 @@ using CommunityToolkit.Maui.Alerts; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; @@ -10,37 +11,24 @@ using ViewModels; namespace LivreLand.ViewModel { - public class ContactsVM : BaseViewModel + [ObservableObject] + public partial class ContactsVM { #region Fields + [ObservableProperty] + private NavigatorVM navigator; + + [ObservableProperty] + private ManagerVM manager; + + [ObservableProperty] private bool dataFormIsVisible = false; #endregion #region Properties - public NavigatorVM Navigator { get; private set; } - - public ManagerVM Manager { get; private set; } - - public bool DataFormIsVisible - { - get { return dataFormIsVisible; } - set - { - if (dataFormIsVisible != value) - { - dataFormIsVisible = value; - OnPropertyChanged(nameof(DataFormIsVisible)); - } - } - } - - public ICommand AddContactDataFormCommand { get; private set; } - - public ICommand BookLendedCommand { get; private set; } - #endregion #region Constructor @@ -49,19 +37,19 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - AddContactDataFormCommand = new RelayCommand(() => AddContactDataForm()); - BookLendedCommand = new RelayCommand((contactVM) => BookLended(contactVM)); } #endregion #region Methods + [RelayCommand] private void AddContactDataForm() { DataFormIsVisible = true; } + [RelayCommand] private async Task BookLended(ContactVM contactVM) { Manager.LendBookCommand.Execute(contactVM); diff --git a/LivreLand/ViewModel/DetailsLivreVM.cs b/LivreLand/ViewModel/DetailsLivreVM.cs index 26f4851..634def5 100644 --- a/LivreLand/ViewModel/DetailsLivreVM.cs +++ b/LivreLand/ViewModel/DetailsLivreVM.cs @@ -1,6 +1,7 @@ using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Model; -using PersonalMVVMToolkit; using System; using System.Collections.Generic; using System.Linq; @@ -11,71 +12,29 @@ using ViewModels; namespace LivreLand.ViewModel { - public class DetailsLivreVM : BaseViewModel + [ObservableObject] + public partial class DetailsLivreVM { #region Fields - private bool isPickerVisible = false; - private string addFavorisButtonText; - - #endregion - - #region Properties - - public ManagerVM Manager { get; private set; } + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public BookVM Book { get; private set; } + [ObservableProperty] + private BookVM book; - public bool IsPickerVisible - { - get => isPickerVisible; - set - { - if (isPickerVisible != value) - { - isPickerVisible = value; - OnPropertyChanged(nameof(IsPickerVisible)); - } - } - } - - public string AddFavorisButtonText - { - get - { - Manager.GetFavoriteBooksCommand.Execute(null); - if (Manager.AllFavoriteBooks.Any(favoriteBook => favoriteBook.Id == Book.Id)) - { - return addFavorisButtonText = "Supprimer des favoris"; - } - else - { - return addFavorisButtonText = "Ajouter aux favoris"; - } - } - set - { - if (addFavorisButtonText != value) - { - addFavorisButtonText = value; - OnPropertyChanged(nameof(AddFavorisButtonText)); - } - } - } - - public ICommand BackButtonCommand { get; private set; } - - public ICommand ShowPickerCommand { get; private set; } - - public ICommand AddRemoveBookToFavoritesCommand { get; private set; } + [ObservableProperty] + private bool isPickerVisible = false; - public ICommand AddBookToReadListCommand { get; private set; } + [ObservableProperty] + private string addFavorisButtonText; - public ICommand LoanBookCommand { get; private set; } + #endregion - public ICommand RemoveBookCommand { get; private set; } + #region Properties #endregion @@ -86,30 +45,27 @@ namespace LivreLand.ViewModel Manager = managerVM; Navigator = navigatorVM; Book = bookVM; - BackButtonCommand = new RelayCommand(() => BackButton()); - ShowPickerCommand = new RelayCommand(() => ShowPicker()); - AddRemoveBookToFavoritesCommand = new RelayCommand((bookVM) => AddRemoveBookToFavorites(bookVM)); - AddBookToReadListCommand = new RelayCommand((bookVM) => AddBookToReadList(bookVM)); - LoanBookCommand = new RelayCommand((bookVM) => LoanBook(bookVM)); - RemoveBookCommand = new RelayCommand((bookVM) => RemoveBook(bookVM)); } #endregion #region Methods + [RelayCommand] private void BackButton() { Navigator.PopupBackButtonNavigationCommand.Execute(null); } + [RelayCommand] private void ShowPicker() { Manager.GetAllStatusCommand.Execute(null); - Manager.SelectedStatus = this.Book.Status; + Manager.SelectedStatus = Book.Status; IsPickerVisible = true; } + [RelayCommand] private async Task AddRemoveBookToFavorites(BookVM bookVM) { Manager.CheckBookIsFavoriteCommand.Execute(bookVM); @@ -139,6 +95,7 @@ namespace LivreLand.ViewModel } } + [RelayCommand] private async Task AddBookToReadList(BookVM bookVM) { Manager.UpdateToBeReadBookCommand.Execute(bookVM); @@ -150,6 +107,7 @@ namespace LivreLand.ViewModel Navigator.NavigationCommand.Execute("/later"); } + [RelayCommand] private void LoanBook(BookVM bookVM) { Manager.SelectedBook = bookVM; @@ -157,6 +115,7 @@ namespace LivreLand.ViewModel Navigator.NavigationCommand.Execute("contacts"); } + [RelayCommand] private async Task RemoveBook(BookVM bookVM) { Manager.RemoveBookCommand.Execute(bookVM); diff --git a/LivreLand/ViewModel/EmpruntsPretsVM.cs b/LivreLand/ViewModel/EmpruntsPretsVM.cs index ea60370..f1fc22d 100644 --- a/LivreLand/ViewModel/EmpruntsPretsVM.cs +++ b/LivreLand/ViewModel/EmpruntsPretsVM.cs @@ -1,6 +1,7 @@ -using LivreLand.View; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using LivreLand.View; using Model; -using PersonalMVVMToolkit; using System; using System.Collections.Generic; using System.Linq; @@ -11,111 +12,39 @@ using ViewModels; namespace LivreLand.ViewModel { - public class EmpruntsPretsVM : BaseViewModel + [ObservableObject] + public partial class EmpruntsPretsVM { #region Fields + [ObservableProperty] + private NavigatorVM navigator; + + [ObservableProperty] + private ManagerVM manager; + + [ObservableProperty] private Color pretButtonBackgroundColor = Colors.White; + + [ObservableProperty] private bool pretButtonIsEnabled = true; + + [ObservableProperty] private Color empruntButtonBackgroundColor = Colors.Transparent; + + [ObservableProperty] private bool empruntButtonIsEnabled = false; + + [ObservableProperty] private bool pretCollectionIsVisible = true; + + [ObservableProperty] private bool empruntCollectionIsVisible = false; #endregion #region Properties - public NavigatorVM Navigator { get; private set; } - - public ManagerVM Manager { get; private set; } - - public Color PretButtonBackgroundColor - { - get { return pretButtonBackgroundColor; } - set - { - if (pretButtonBackgroundColor != value) - { - pretButtonBackgroundColor = value; - OnPropertyChanged(nameof(PretButtonBackgroundColor)); - } - } - } - - public bool PretButtonIsEnabled - { - get { return pretButtonIsEnabled; } - set - { - if (pretButtonIsEnabled != value) - { - pretButtonIsEnabled = value; - OnPropertyChanged(nameof(PretButtonIsEnabled)); - } - } - } - - public Color EmpruntButtonBackgroundColor - { - get { return empruntButtonBackgroundColor; } - set - { - if (empruntButtonBackgroundColor != value) - { - empruntButtonBackgroundColor = value; - OnPropertyChanged(nameof(EmpruntButtonBackgroundColor)); - } - } - } - - public bool EmpruntButtonIsEnabled - { - get { return empruntButtonIsEnabled; } - set - { - if (empruntButtonIsEnabled != value) - { - empruntButtonIsEnabled = value; - OnPropertyChanged(nameof(EmpruntButtonIsEnabled)); - } - } - } - - public bool EmpruntCollectionIsVisible - { - get { return empruntCollectionIsVisible; } - set - { - if (empruntCollectionIsVisible != value) - { - empruntCollectionIsVisible = value; - OnPropertyChanged(nameof(EmpruntCollectionIsVisible)); - } - } - } - - public bool PretCollectionIsVisible - { - get { return pretCollectionIsVisible; } - set - { - if (pretCollectionIsVisible != value) - { - pretCollectionIsVisible = value; - OnPropertyChanged(nameof(PretCollectionIsVisible)); - } - } - } - - public ICommand OnSelectionLoanChangedCommand { get; private set; } - - public ICommand OnSelectionBorrowingChangedCommand { get; private set; } - - public ICommand PretsButtonCommand { get; private set; } - - public ICommand EmpruntsButtonCommand { get; private set; } - #endregion #region Constructor @@ -124,21 +53,18 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - OnSelectionLoanChangedCommand = new RelayCommand((loanVM) => OnSelectionLoanChanged(loanVM)); - OnSelectionBorrowingChangedCommand = new RelayCommand((borrowingVM) => OnSelectionBorrowingChanged(borrowingVM)); - PretsButtonCommand = new RelayCommand(() => PretsButtonClicked()); - EmpruntsButtonCommand = new RelayCommand(() => EmpruntsButtonClicked()); } #endregion #region Methods + [RelayCommand] private void OnSelectionLoanChanged(LoanVM loanVM) { if (loanVM != null) { - foreach (var b in Manager.AllCurrentLoans) + foreach (var b in Manager.CurrentLoans) { if (b.Book.Id == loanVM.Book.Id) { @@ -150,11 +76,12 @@ namespace LivreLand.ViewModel } } + [RelayCommand] private void OnSelectionBorrowingChanged(BorrowingVM borrowingVM) { if (borrowingVM != null) { - foreach (var b in Manager.AllCurrentBorrowings) + foreach (var b in Manager.CurrentBorrowings) { if (b.Book.Id == borrowingVM.Book.Id) { @@ -166,6 +93,7 @@ namespace LivreLand.ViewModel } } + [RelayCommand] public void PretsButtonClicked() { if (App.Current.PlatformAppTheme == AppTheme.Light) @@ -186,6 +114,7 @@ namespace LivreLand.ViewModel EmpruntCollectionIsVisible = true; } + [RelayCommand] public void EmpruntsButtonClicked() { if (App.Current.PlatformAppTheme == AppTheme.Light) diff --git a/LivreLand/ViewModel/FavorisVM.cs b/LivreLand/ViewModel/FavorisVM.cs index c69ae28..b698324 100644 --- a/LivreLand/ViewModel/FavorisVM.cs +++ b/LivreLand/ViewModel/FavorisVM.cs @@ -1,4 +1,4 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; using System; using System.Collections.Generic; using System.Linq; @@ -8,13 +8,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class FavorisVM : BaseViewModel + [ObservableObject] + public partial class FavorisVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion + + #region Properties #endregion diff --git a/LivreLand/ViewModel/FiltrageAuteurVM.cs b/LivreLand/ViewModel/FiltrageAuteurVM.cs index 8927af6..248124e 100644 --- a/LivreLand/ViewModel/FiltrageAuteurVM.cs +++ b/LivreLand/ViewModel/FiltrageAuteurVM.cs @@ -1,4 +1,5 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; @@ -9,15 +10,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class FiltrageAuteurVM : BaseViewModel + [ObservableObject] + public partial class FiltrageAuteurVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion - public ICommand NavigateAuthorPageCommand { get; private set; } + #region Properties #endregion @@ -27,13 +33,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - NavigateAuthorPageCommand = new RelayCommand(() => NavigateAuthorPage()); } #endregion #region Methods + [RelayCommand] private void NavigateAuthorPage() { Manager.GetBooksByAuthorCommand.Execute(null); diff --git a/LivreLand/ViewModel/FiltrageDateVM.cs b/LivreLand/ViewModel/FiltrageDateVM.cs index 2ee0f3e..3619897 100644 --- a/LivreLand/ViewModel/FiltrageDateVM.cs +++ b/LivreLand/ViewModel/FiltrageDateVM.cs @@ -1,4 +1,5 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; @@ -9,15 +10,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class FiltrageDateVM : BaseViewModel + [ObservableObject] + public partial class FiltrageDateVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion - public ICommand NavigateDatePageCommand { get; private set; } + #region Properties #endregion @@ -27,13 +33,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - NavigateDatePageCommand = new RelayCommand(() => NavigateDatePage()); } #endregion #region Methods + [RelayCommand] private void NavigateDatePage() { Manager.GetBooksByDateCommand.Execute(null); diff --git a/LivreLand/ViewModel/FiltrageNoteVM.cs b/LivreLand/ViewModel/FiltrageNoteVM.cs index d70f162..b083cd2 100644 --- a/LivreLand/ViewModel/FiltrageNoteVM.cs +++ b/LivreLand/ViewModel/FiltrageNoteVM.cs @@ -1,4 +1,5 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; @@ -9,15 +10,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class FiltrageNoteVM : BaseViewModel + [ObservableObject] + public partial class FiltrageNoteVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion - public ICommand NavigateRatingPageCommand { get; private set; } + #region Properties #endregion @@ -27,13 +33,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - NavigateRatingPageCommand = new RelayCommand(() => NavigateRatingPage()); } #endregion #region Methods + [RelayCommand] private void NavigateRatingPage() { Manager.GetBooksByRatingCommand.Execute(null); diff --git a/LivreLand/ViewModel/NavigatorVM.cs b/LivreLand/ViewModel/NavigatorVM.cs index a93d9e4..4356080 100644 --- a/LivreLand/ViewModel/NavigatorVM.cs +++ b/LivreLand/ViewModel/NavigatorVM.cs @@ -1,4 +1,6 @@ using CommunityToolkit.Maui.Views; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using LivreLand.View; using LivreLand.View.ContentViews; using System; @@ -10,14 +12,14 @@ using System.Windows.Input; namespace LivreLand.ViewModel { - public class NavigatorVM + [ObservableObject] + public partial class NavigatorVM { - #region Properties + #region Fields + + #endregion - public ICommand NavigationCommand { get; } - public ICommand PopupHomePlusNavigationCommand { get; } - public ICommand PopupISBNNavigationCommand { get; } - public ICommand PopupBackButtonNavigationCommand { get; } + #region Properties #endregion @@ -25,17 +27,37 @@ namespace LivreLand.ViewModel public NavigatorVM() { - NavigationCommand = new Command(async (target) => await Shell.Current.GoToAsync($"//library/{target}")); - PopupHomePlusNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupHomePlusButtonView(this))); - PopupISBNNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupISBNView(Application.Current.Handler.MauiContext.Services.GetService()))); - PopupBackButtonNavigationCommand = new Command(() => App.Current.MainPage.Navigation.PopAsync()); } #endregion #region Methods + [RelayCommand] + private async Task Navigation(string target) + { + await Shell.Current.GoToAsync($"//library/{target}"); + } + + [RelayCommand] + private async Task PopupHomePlusNavigation() + { + await App.Current.MainPage.ShowPopupAsync(new PopupHomePlusButtonView(this)); + } + + [RelayCommand] + private async Task PopupISBNNavigation() + { + await App.Current.MainPage.ShowPopupAsync(new PopupISBNView(Application.Current.Handler.MauiContext.Services.GetService())); + } + + [RelayCommand] + private async Task PopupBackButtonNavigation() + { + await App.Current.MainPage.Navigation.PopAsync(); + } + #endregion } } diff --git a/LivreLand/ViewModel/PopupISBNVM.cs b/LivreLand/ViewModel/PopupISBNVM.cs index 557ae31..ced1e10 100644 --- a/LivreLand/ViewModel/PopupISBNVM.cs +++ b/LivreLand/ViewModel/PopupISBNVM.cs @@ -1,6 +1,7 @@ using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Model; -using PersonalMVVMToolkit; using System; using System.Collections.Generic; using System.Linq; @@ -11,15 +12,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class PopupISBNVM : BaseViewModel + [ObservableObject] + public partial class PopupISBNVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion - public ICommand AddBookCommand { get; private set; } + #region Properties #endregion @@ -29,13 +35,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - AddBookCommand = new RelayCommand((text) => AddBook(text)); } #endregion #region Methods + [RelayCommand] private async Task AddBook(string entryText) { Manager.AddBookCommand.Execute(entryText); diff --git a/LivreLand/ViewModel/ScanVM.cs b/LivreLand/ViewModel/ScanVM.cs index 4724afd..d0c1d86 100644 --- a/LivreLand/ViewModel/ScanVM.cs +++ b/LivreLand/ViewModel/ScanVM.cs @@ -1,6 +1,7 @@ using Camera.MAUI; using CommunityToolkit.Maui.Alerts; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -13,60 +14,39 @@ using ZXing; namespace LivreLand.ViewModel { - public class ScanVM : BaseViewModel + [ObservableObject] + public partial class ScanVM { #region Fields + [ObservableProperty] + private NavigatorVM navigator; + + [ObservableProperty] + private ManagerVM manager; + + [ObservableProperty] private CameraView cameraView; + + [ObservableProperty] private CameraInfo camera = null; + + [ObservableProperty] private ObservableCollection cameras = new(); + + [ObservableProperty] private Result[] result; + + [ObservableProperty] private string barcodeText = "ISBN"; + + [ObservableProperty] private bool addIsVisible = false; #endregion #region Properties - public CameraView CameraView - { - get => cameraView; - set - { - if (cameraView != value) - { - cameraView = value; - OnPropertyChanged(nameof(CameraView)); - } - } - } - - public CameraInfo Camera - { - get => camera; - set - { - if (camera != value) - { - camera = value; - OnPropertyChanged(nameof(Camera)); - } - } - } - - public ObservableCollection Cameras - { - get => cameras; - set - { - if (cameras != value) - { - cameras = value; - OnPropertyChanged(nameof(Cameras)); - } - } - } - public int CamerasCount { get => Cameras.Count(); @@ -92,42 +72,6 @@ namespace LivreLand.ViewModel } } - public string BarcodeText - { - get => barcodeText; - set - { - if (barcodeText != value) - { - barcodeText = value; - OnPropertyChanged(nameof(BarcodeText)); - } - } - } - - public bool AddIsVisible - { - get => addIsVisible; - set - { - if (addIsVisible != value) - { - addIsVisible = value; - OnPropertyChanged(nameof(AddIsVisible)); - } - } - } - - public NavigatorVM Navigator { get; private set; } - - public ManagerVM Manager { get; private set; } - - public ICommand CamerasLoadCommand { get; private set; } - - public ICommand BarcodeDetectCommand { get; private set; } - - public ICommand AddBookISBNDetectedCommand { get; private set; } - #endregion #region Constructor @@ -136,15 +80,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - CamerasLoadCommand = new RelayCommand(() => CamerasLoad()); - BarcodeDetectCommand = new RelayCommand(() => BarcodeDetect()); - AddBookISBNDetectedCommand = new RelayCommand((isbn) => AddBookISBNDetected(isbn)); } #endregion #region Methods + [RelayCommand] private async Task CamerasLoad() { if (Cameras.Count > 0) @@ -158,6 +100,7 @@ namespace LivreLand.ViewModel } } + [RelayCommand] private async Task BarcodeDetect() { MainThread.BeginInvokeOnMainThread(() => @@ -167,6 +110,7 @@ namespace LivreLand.ViewModel }); } + [RelayCommand] private async Task AddBookISBNDetected(string isbn) { Manager.AddBookCommand.Execute(isbn); diff --git a/LivreLand/ViewModel/StatutLectureVM.cs b/LivreLand/ViewModel/StatutLectureVM.cs index 1dbeba6..564708c 100644 --- a/LivreLand/ViewModel/StatutLectureVM.cs +++ b/LivreLand/ViewModel/StatutLectureVM.cs @@ -1,5 +1,6 @@ -using LivreLand.View; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using LivreLand.View; using System; using System.Collections.Generic; using System.Linq; @@ -10,15 +11,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class StatutLectureVM : BaseViewModel + [ObservableObject] + public partial class StatutLectureVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion - public ICommand OnSelectionChangedCommand { get; private set; } + #region Properties #endregion @@ -28,13 +34,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - OnSelectionChangedCommand = new RelayCommand((bookVM) => OnSelectionChanged(bookVM)); } #endregion #region Methods + [RelayCommand] private void OnSelectionChanged(BookVM bookVM) { if (bookVM != null) diff --git a/LivreLand/ViewModel/TousVM.cs b/LivreLand/ViewModel/TousVM.cs index f1ba534..0cea40c 100644 --- a/LivreLand/ViewModel/TousVM.cs +++ b/LivreLand/ViewModel/TousVM.cs @@ -1,5 +1,6 @@ -using LivreLand.View; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using LivreLand.View; using System; using System.Collections.Generic; using System.Linq; @@ -10,15 +11,20 @@ using ViewModels; namespace LivreLand.ViewModel { - public class TousVM : BaseViewModel + [ObservableObject] + public partial class TousVM { - #region Properties + #region Fields + + [ObservableProperty] + private NavigatorVM navigator; - public NavigatorVM Navigator { get; private set; } + [ObservableProperty] + private ManagerVM manager; - public ManagerVM Manager { get; private set; } + #endregion - public ICommand OnSelectionChangedCommand { get; private set; } + #region Properties #endregion @@ -28,13 +34,13 @@ namespace LivreLand.ViewModel { Navigator = navigatorVM; Manager = managerVM; - OnSelectionChangedCommand = new RelayCommand((bookVM) => OnSelectionChanged(bookVM)); } #endregion #region Methods + [RelayCommand] private void OnSelectionChanged(BookVM bookVM) { if (bookVM != null) diff --git a/Model/Model.csproj b/Model/Model.csproj index cfadb03..d87a0e0 100644 --- a/Model/Model.csproj +++ b/Model/Model.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/PersonalMVVMToolkit/PersonalMVVMToolkit.csproj b/PersonalMVVMToolkit/PersonalMVVMToolkit.csproj index cfadb03..d87a0e0 100644 --- a/PersonalMVVMToolkit/PersonalMVVMToolkit.csproj +++ b/PersonalMVVMToolkit/PersonalMVVMToolkit.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/Stub/Stub.csproj b/Stub/Stub.csproj index a0f8166..6062d90 100644 --- a/Stub/Stub.csproj +++ b/Stub/Stub.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/StubbedDTO/StubbedDTO.csproj b/StubbedDTO/StubbedDTO.csproj index e600184..a3714d0 100644 --- a/StubbedDTO/StubbedDTO.csproj +++ b/StubbedDTO/StubbedDTO.csproj @@ -33,4 +33,8 @@ + + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 89f70e9..6f0a0ea 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -7,6 +7,11 @@ enable + + + + + diff --git a/Utils/Utils.csproj b/Utils/Utils.csproj index cfadb03..d87a0e0 100644 --- a/Utils/Utils.csproj +++ b/Utils/Utils.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/ViewModels/AuthorVM.cs b/ViewModels/AuthorVM.cs index 8072008..0b931e9 100644 --- a/ViewModels/AuthorVM.cs +++ b/ViewModels/AuthorVM.cs @@ -1,5 +1,5 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -8,40 +8,27 @@ using System.Threading.Tasks; namespace ViewModels { - public class AuthorVM : BaseViewModel + [ObservableObject] + public partial class AuthorVM { #region Fields - private int nbBooksWritten { get; set; } + [ObservableProperty] + private int nbBooksWritten; + + [ObservableProperty] + private string name; #endregion #region Properties - public string Name - { - get => Model.Name; - set - { - Model.Name = value; - } - } - - public int NbBooksWritten - { - get => nbBooksWritten; - set - { - nbBooksWritten = value; - } - } - #endregion #region Constructor - public AuthorVM(Author model) : base(model) + public AuthorVM(Author model) { } diff --git a/ViewModels/BookVM.cs b/ViewModels/BookVM.cs index 6b38162..89de8cd 100644 --- a/ViewModels/BookVM.cs +++ b/ViewModels/BookVM.cs @@ -1,5 +1,5 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -8,82 +8,57 @@ using System.Threading.Tasks; namespace ViewModels { - public class BookVM : BaseViewModel + [ObservableObject] + public partial class BookVM { #region Fields - #endregion + [ObservableProperty] + private string id; - #region Properties + [ObservableProperty] + private string isbn13; - public string Id - { - get => Model.Id; - } + [ObservableProperty] + private string title; - public string ISBN13 - { - get => Model.ISBN13; - } + [ObservableProperty] + private List publishers; - public string Title - { - get => Model.Title; - } + [ObservableProperty] + private DateTime publishDate; - public List Publishers - { - get => Model.Publishers; - } + [ObservableProperty] + private List authors; - public DateTime PublishDate - { - get => Model.PublishDate; - } + [ObservableProperty] + private string author; - public List Authors - { - get => Model.Authors.Select(a => new AuthorVM(a)).ToList(); - } + [ObservableProperty] + private Status status; - public string Author => Model.Authors.Count > 0 ? Model.Authors.First().Name : "Auteur inconnu"; + [ObservableProperty] + private int nbPages; - public Status Status - { - get => Model.Status; - } + [ObservableProperty] + private Languages language; - public int NbPages - { - get => Model.NbPages; - } + [ObservableProperty] + private string imageSmall; - public Languages Language - { - get => Model.Language; - } + [ObservableProperty] + private float? userRating; - public string ImageSmall - { - get => Model.ImageSmall; - } + #endregion - public float? UserRating - { - get => Model?.UserRating; - set - { - if (Model == null) return; - SetProperty(Model.UserRating, value, rating => Model.UserRating = rating); - } - } + #region Properties #endregion #region Constructor - public BookVM(Book b) : base(b) + public BookVM(Book b) { } diff --git a/ViewModels/BorrowingVM.cs b/ViewModels/BorrowingVM.cs index 13a0f9e..6725f72 100644 --- a/ViewModels/BorrowingVM.cs +++ b/ViewModels/BorrowingVM.cs @@ -1,5 +1,5 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -8,47 +8,35 @@ using System.Threading.Tasks; namespace ViewModels { - public class BorrowingVM : BaseViewModel + [ObservableObject] + public partial class BorrowingVM { #region Fields - #endregion + [ObservableProperty] + private string id; - #region Properties + [ObservableProperty] + private BookVM book; - public string Id - { - get => Model.Id; - set => SetProperty(Model.Id, value, v => Model.Id = value); - } + [ObservableProperty] + private ContactVM owner; - public BookVM Book - { - get => new BookVM(Model.Book); - } + [ObservableProperty] + private DateTime borrowedAt; - public ContactVM Owner - { - get => new ContactVM(Model.Owner); - } + [ObservableProperty] + private DateTime returnedAt; - public DateTime BorrowedAt - { - get => Model.BorrowedAt; - set => SetProperty(Model.BorrowedAt, value, v => Model.BorrowedAt = value); - } + #endregion - public DateTime? ReturnedAt - { - get => Model.ReturnedAt; - set => SetProperty(Model.ReturnedAt, value, v => Model.ReturnedAt = value); - } + #region Properties #endregion #region Constructor - public BorrowingVM(Borrowing b) : base(b) + public BorrowingVM(Borrowing b) { } diff --git a/ViewModels/ContactVM.cs b/ViewModels/ContactVM.cs index 7e2d1b0..959b908 100644 --- a/ViewModels/ContactVM.cs +++ b/ViewModels/ContactVM.cs @@ -1,5 +1,5 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -8,37 +8,29 @@ using System.Threading.Tasks; namespace ViewModels { - public class ContactVM : BaseViewModel + [ObservableObject] + public partial class ContactVM { #region Fields - #endregion + [ObservableProperty] + private string id; - #region Properties + [ObservableProperty] + private string firstName; - public string Id - { - get => Model.Id; - set => SetProperty(Model.Id, value, v => Model.Id = value); - } + [ObservableProperty] + private string lastName; - public string FirstName - { - get => Model.FirstName; - set => SetProperty(Model.FirstName, value, v => Model.FirstName = value); - } + #endregion - public string LastName - { - get => Model.LastName; - set => SetProperty(Model.LastName, value, v => Model.LastName = value); - } + #region Properties #endregion #region Constructor - public ContactVM(Model.Contact c) : base(c) + public ContactVM(Model.Contact c) { } diff --git a/ViewModels/LoanVM.cs b/ViewModels/LoanVM.cs index 05ec4bb..21d92b3 100644 --- a/ViewModels/LoanVM.cs +++ b/ViewModels/LoanVM.cs @@ -1,5 +1,5 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -8,47 +8,35 @@ using System.Threading.Tasks; namespace ViewModels { - public class LoanVM : BaseViewModel + [ObservableObject] + public partial class LoanVM { #region Fields - #endregion + [ObservableProperty] + private string id; - #region Properties + [ObservableProperty] + private BookVM book; - public string Id - { - get => Model.Id; - set => SetProperty(Model.Id, value, v => Model.Id = value); - } + [ObservableProperty] + private ContactVM loaner; - public BookVM Book - { - get => new BookVM(Model.Book); - } + [ObservableProperty] + private DateTime loanedAt; - public ContactVM Loaner - { - get => new ContactVM(Model.Loaner); - } + [ObservableProperty] + private DateTime? returnedAt; - public DateTime LoanedAt - { - get => Model.LoanedAt; - set => SetProperty(Model.LoanedAt, value, v => Model.LoanedAt = value); - } + #endregion - public DateTime? ReturnedAt - { - get => Model.ReturnedAt; - set => SetProperty(Model.ReturnedAt, value, v => Model.ReturnedAt = value); - } + #region Properties #endregion #region Constructor - public LoanVM(Loan l) : base(l) + public LoanVM(Loan l) { } diff --git a/ViewModels/ManagerVM.cs b/ViewModels/ManagerVM.cs index 621bd5d..f601780 100644 --- a/ViewModels/ManagerVM.cs +++ b/ViewModels/ManagerVM.cs @@ -1,5 +1,6 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Model; using System.Collections.ObjectModel; using System.Linq; using System.Text.RegularExpressions; @@ -8,419 +9,128 @@ using static System.Reflection.Metadata.BlobBuilder; namespace ViewModels { - public class ManagerVM : BaseViewModel + [ObservableObject] + public partial class ManagerVM { #region Fields - private readonly ObservableCollection books = new ObservableCollection(); - private IEnumerable> groupedBooks; - private IEnumerable> groupedStatusBooks; + [ObservableProperty] + private Manager model; - private readonly ObservableCollection authors = new ObservableCollection(); - private readonly ObservableCollection publishDates = new ObservableCollection(); - private readonly ObservableCollection ratings = new ObservableCollection(); + [ObservableProperty] + private ObservableCollection books = new ObservableCollection(); - private readonly ObservableCollection toBeReadBooks = new ObservableCollection(); - private readonly ObservableCollection favoriteBooks = new ObservableCollection(); - - private readonly ObservableCollection currentLoans = new ObservableCollection(); - private IEnumerable> currentGroupedLoans; - private readonly ObservableCollection pastLoans = new ObservableCollection(); - private IEnumerable> pastGroupedLoans; - - private readonly ObservableCollection currentBorrowings = new ObservableCollection(); - private IEnumerable> currentGroupedBorrowings; - private readonly ObservableCollection pastBorrowings = new ObservableCollection(); - private IEnumerable> pastGroupedBorrowings; - - private readonly ObservableCollection contacts = new ObservableCollection(); - private readonly ObservableCollection status = new ObservableCollection(); - - private int index; - private long nbBooks; - - private BookVM selectedBook; - private AuthorVM selectedAuthor; - private PublishDateVM selectedDate; - private RatingsVM selectedRating; - private Status selectedStatus; - private ContactVM selectedContact; - private LoanVM selectedLoan; - private BorrowingVM selectedBorrowing; - private string entryText; + [ObservableProperty] + private IEnumerable> groupedBooks; - private string givenFirstName; - private string givenLastName; - private bool isFavorite; + [ObservableProperty] + private IEnumerable> groupedStatusBooks; - #endregion + [ObservableProperty] + private ObservableCollection authors = new ObservableCollection(); - #region Properties + [ObservableProperty] + private ObservableCollection publishDates = new ObservableCollection(); - public ObservableCollection AllBooks - { - get => books; - } + [ObservableProperty] + private ObservableCollection ratings = new ObservableCollection(); - public IEnumerable> GroupedBooks - { - get => groupedBooks; - set => SetProperty(ref groupedBooks, value); - } + [ObservableProperty] + private ObservableCollection toBeReadBooks = new ObservableCollection(); - public IEnumerable> GroupedStatusBooks - { - get => groupedStatusBooks; - set => SetProperty(ref groupedStatusBooks, value); - } + [ObservableProperty] + private ObservableCollection favoriteBooks = new ObservableCollection(); - public ObservableCollection AllAuthors - { - get => authors; - } + [ObservableProperty] + private ObservableCollection currentLoans = new ObservableCollection(); - public ObservableCollection AllPublishDates - { - get => publishDates; - } + [ObservableProperty] + private IEnumerable> currentGroupedLoans; - public ObservableCollection AllRatings - { - get => ratings; - } + [ObservableProperty] + private ObservableCollection pastLoans = new ObservableCollection(); - public ObservableCollection ToBeReadBooks - { - get => toBeReadBooks; - } + [ObservableProperty] + private IEnumerable> pastGroupedLoans; - public ObservableCollection AllFavoriteBooks - { - get => favoriteBooks; - } + [ObservableProperty] + private ObservableCollection currentBorrowings = new ObservableCollection(); - public ObservableCollection AllCurrentLoans - { - get => currentLoans; - } + [ObservableProperty] + private IEnumerable> currentGroupedBorrowings; - public IEnumerable> AllCurrentGroupedLoans - { - get => currentGroupedLoans; - set => SetProperty(ref currentGroupedLoans, value); - } + [ObservableProperty] + private ObservableCollection pastBorrowings = new ObservableCollection(); - public ObservableCollection AllPastLoans - { - get => pastLoans; - } + [ObservableProperty] + private IEnumerable> pastGroupedBorrowings; - public IEnumerable> AllPastGroupedLoans - { - get => pastGroupedLoans; - set => SetProperty(ref pastGroupedLoans, value); - } + [ObservableProperty] + private ObservableCollection contacts = new ObservableCollection(); - public ObservableCollection AllCurrentBorrowings - { - get => currentBorrowings; - } + [ObservableProperty] + private ObservableCollection allStatus = new ObservableCollection(); - public IEnumerable> AllCurrentGroupedBorrowings - { - get => currentGroupedBorrowings; - set => SetProperty(ref currentGroupedBorrowings, value); - } - - public ObservableCollection AllPastBorrowings - { - get => pastBorrowings; - } + [ObservableProperty] + private int indexPage; - public IEnumerable> AllPastGroupedBorrowings - { - get => pastGroupedBorrowings; - set => SetProperty(ref pastGroupedBorrowings, value); - } + [ObservableProperty] + private long nbBooks; - public ObservableCollection AllContacts - { - get => contacts; - } + [ObservableProperty] + private BookVM selectedBook; - public ObservableCollection AllStatus - { - get => status; - } + [ObservableProperty] + private AuthorVM selectedAuthor; - public BookVM SelectedBook - { - get { return selectedBook; } - set - { - if (selectedBook != value) - { - selectedBook = value; - OnPropertyChanged(nameof(SelectedBook)); - } - } - } + [ObservableProperty] + private PublishDateVM selectedDate; - public AuthorVM SelectedAuthor - { - get { return selectedAuthor; } - set - { - if (selectedAuthor != value) - { - selectedAuthor = value; - OnPropertyChanged(nameof(SelectedAuthor)); - } - } - } + [ObservableProperty] + private RatingsVM selectedRating; - public PublishDateVM SelectedDate - { - get { return selectedDate; } - set - { - if (selectedDate != value) - { - selectedDate = value; - OnPropertyChanged(nameof(SelectedDate)); - } - } - } + [ObservableProperty] + private Status selectedStatus; - public RatingsVM SelectedRating - { - get { return selectedRating; } - set - { - if (selectedRating != value) - { - selectedRating = value; - OnPropertyChanged(nameof(SelectedRating)); - } - } - } + [ObservableProperty] + private ContactVM selectedContact; - public Status SelectedStatus - { - get { return selectedStatus; } - set - { - if (selectedStatus != value) - { - selectedStatus = value; - OnPropertyChanged(nameof(SelectedStatus)); - } - } - } + [ObservableProperty] + private LoanVM selectedLoan; - public ContactVM SelectedContact - { - get { return selectedContact; } - set - { - if (selectedContact != value) - { - selectedContact = value; - OnPropertyChanged(nameof(SelectedContact)); - } - } - } + [ObservableProperty] + private BorrowingVM selectedBorrowing; - public LoanVM SelectedLoan - { - get { return selectedLoan; } - set - { - if (selectedLoan != value) - { - selectedLoan = value; - OnPropertyChanged(nameof(SelectedLoan)); - } - } - } + [ObservableProperty] + private string entryText; - public BorrowingVM SelectedBorrowing - { - get { return selectedBorrowing; } - set - { - if (selectedBorrowing != value) - { - selectedBorrowing = value; - OnPropertyChanged(nameof(SelectedBorrowing)); - } - } - } + [ObservableProperty] + private string givenFirstName; - public string EntryText - { - get { return entryText; } - set - { - if (entryText != value) - { - entryText = value; - OnPropertyChanged(nameof(EntryText)); - } - } - } + [ObservableProperty] + private string givenLastName; - public string GivenFirstName - { - get { return givenFirstName; } - set - { - if (givenFirstName != value) - { - givenFirstName = value; - OnPropertyChanged(nameof(GivenFirstName)); - } - } - } + [ObservableProperty] + private bool isFavorite; - public string GivenLastName - { - get { return givenLastName; } - set - { - if (givenLastName != value) - { - givenLastName = value; - OnPropertyChanged(nameof(GivenLastName)); - } - } - } + #endregion - public bool IsFavorite - { - get { return isFavorite; } - set - { - if (isFavorite != value) - { - isFavorite = value; - OnPropertyChanged(nameof(IsFavorite)); - } - } - } + #region Properties public string SearchTitle { get; private set; } - public int Index - { - get => index; - set => SetProperty(ref index, value); - } - public int Count { get; set; } = 5; - public long NbBooks - { - get => nbBooks; - set - { - SetProperty(ref nbBooks, value); - OnPropertyChanged(nameof(NbPages)); - } - } - public int NbPages => (int)((NbBooks - 1) / Count); - public ICommand PreviousCommand { get; private set; } - - public ICommand NextCommand { get; private set; } - - public ICommand GetBooksByTitleCommand { get; private set; } - - public ICommand GetBooksFromCollectionCommand { get; private set; } - - public ICommand AddBookCommand { get; private set; } - - public ICommand UpdateBookCommand { get; private set; } - - public ICommand UpdateStatusBookCommand { get; private set; } - - public ICommand UpdateToBeReadBookCommand { get; private set; } - - public ICommand RemoveBookCommand { get; private set; } - - public ICommand GetBooksByAuthorCommand { get; private set; } - - public ICommand GetAllAuthorsCommand { get; private set; } - - public ICommand GetBooksByDateCommand { get; private set; } - - public ICommand GetAllPublishDatesCommand { get; private set; } - - public ICommand GetBooksByRatingCommand { get; private set; } - - public ICommand GetAllRatingsCommand { get; private set; } - - public ICommand GetAllStatusCommand { get; private set; } - - public ICommand GetToBeReadBooksCommand { get; private set; } - - public ICommand GetFavoriteBooksCommand { get; private set; } - - public ICommand AddToFavoritesCommand { get; private set; } - - public ICommand RemoveFromFavoritesCommand { get; private set; } - - public ICommand CheckBookIsFavoriteCommand { get; private set; } - - public ICommand GetCurrentLoansCommand { get; private set; } - - public ICommand GetPastLoansCommand { get; private set; } - - public ICommand GetCurrentBorrowingsCommand { get; private set; } - - public ICommand GetPastBorrowingsCommand { get; private set; } - - public ICommand LendBookCommand { get; private set; } - - public ICommand GetContactsCommand { get; private set; } - - public ICommand AddContactCommand { get; private set; } - #endregion #region Constructor - public ManagerVM(Manager model) : base(model) + public ManagerVM(Manager model) { - PreviousCommand = new RelayCommand(() => Previous()); - NextCommand = new RelayCommand(() => Next()); - GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection()); - AddBookCommand = new RelayCommand((isbn) => AddBook(isbn)); - UpdateBookCommand = new RelayCommand((bookVM) => UpdateBook(bookVM)); - UpdateStatusBookCommand = new RelayCommand((bookVM) => UpdateStatusBook(bookVM)); - UpdateToBeReadBookCommand = new RelayCommand((bookVM) => UpdateToBeReadBook(bookVM)); - RemoveBookCommand = new RelayCommand((bookVM) => RemoveBook(bookVM)); - GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor()); - GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors()); - GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate()); - GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates()); - GetBooksByRatingCommand = new RelayCommand(() => GetBooksByRating()); - GetAllRatingsCommand = new RelayCommand(() => GetAllRatings()); - GetAllStatusCommand = new RelayCommand(() => GetAllStatus()); - GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks()); - GetFavoriteBooksCommand = new RelayCommand(() => GetFavoriteBooks()); - AddToFavoritesCommand = new RelayCommand(bookVM => AddToFavorites(bookVM)); - RemoveFromFavoritesCommand = new RelayCommand(bookVM => RemoveFromFavorites(bookVM)); - CheckBookIsFavoriteCommand = new RelayCommand(bookVM => CheckBookIsFavorite(bookVM)); - GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans()); - GetPastLoansCommand = new RelayCommand(() => GetPastLoans()); - GetCurrentBorrowingsCommand = new RelayCommand(() => GetCurrentBorrowings()); - GetPastBorrowingsCommand = new RelayCommand(() => GetPastBorrowings()); - LendBookCommand = new RelayCommand((contactVM) => LendBook(contactVM)); - GetContactsCommand = new RelayCommand(() => GetContacts()); - AddContactCommand = new RelayCommand(() => AddContact()); + Model = model; //GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book))); } @@ -430,41 +140,45 @@ namespace ViewModels #region Methods + [RelayCommand] private async Task Previous() { - if (Index > 0) + if (IndexPage > 0) { - Index--; + IndexPage--; await GetBooksFromCollection(); } } + [RelayCommand] private async Task Next() { - if (Index < NbPages) + if (IndexPage < NbPages) { - Index++; + IndexPage++; await GetBooksFromCollection(); } } + [RelayCommand] private async Task GetBooksFromCollection() { - var result = await Model.GetBooksFromCollection(Index, Count); + var result = await Model.GetBooksFromCollection(IndexPage, Count); NbBooks = result.count; IEnumerable someBooks = result.books; someBooks = someBooks.OrderBy(b => b.Status); - books.Clear(); + Books.Clear(); foreach (var b in someBooks.Select(b => new BookVM(b))) { - books.Add(b); - GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); - GroupedStatusBooks = AllBooks.GroupBy(b => b.Status).OrderBy(group => group.Key); + Books.Add(b); + GroupedBooks = Books.GroupBy(b => b.Author).OrderBy(group => group.Key); + GroupedStatusBooks = Books.GroupBy(b => b.Status).OrderBy(group => group.Key); } OnPropertyChanged(nameof(GroupedBooks)); - OnPropertyChanged(nameof(AllBooks)); + OnPropertyChanged(nameof(Books)); } + [RelayCommand] private async Task AddBook(string isbn) { var result = await Model.GetBookByISBN(isbn); @@ -475,12 +189,14 @@ namespace ViewModels GetBooksFromCollectionCommand.Execute(null); } + [RelayCommand] private async Task UpdateBook(BookVM bookVM) { var book = await Model.GetBookById(bookVM.Id); await Model.UpdateBook(book); } - + + [RelayCommand] private async Task UpdateStatusBook(BookVM bookVM) { var book = await Model.GetBookById(bookVM.Id); @@ -491,6 +207,7 @@ namespace ViewModels OnPropertyChanged(nameof(bookVM)); } + [RelayCommand] private async Task UpdateToBeReadBook(BookVM bookVM) { var book = await Model.GetBookById(bookVM.Id); @@ -498,6 +215,7 @@ namespace ViewModels await Model.UpdateBook(book); } + [RelayCommand] private async Task RemoveBook(BookVM bookVM) { var book = await Model.GetBookById(bookVM.Id); @@ -506,6 +224,7 @@ namespace ViewModels await GetBooksFromCollection(); } + [RelayCommand] private async Task GetBooksByAuthor() { var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, 0, 1000); @@ -515,12 +234,13 @@ namespace ViewModels foreach (var b in someBooks.Select(b => new BookVM(b))) { books.Add(b); - GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); + GroupedBooks = Books.GroupBy(b => b.Author).OrderBy(group => group.Key); } OnPropertyChanged(nameof(GroupedBooks)); - OnPropertyChanged(nameof(AllBooks)); + OnPropertyChanged(nameof(Books)); } + [RelayCommand] private async Task GetAllAuthors() { var result = await Model.GetBooksFromCollection(0, 1000); @@ -535,9 +255,10 @@ namespace ViewModels a.NbBooksWritten++; } } - OnPropertyChanged(nameof(AllAuthors)); + OnPropertyChanged(nameof(Authors)); } + [RelayCommand] private async Task GetBooksByDate() { var result = await Model.GetBooksFromCollection(0, 1000); @@ -549,42 +270,44 @@ namespace ViewModels if (b.PublishDate.Year == SelectedDate.PublishDate.Year) { books.Add(b); - GroupedBooks = AllBooks.GroupBy(b => b.PublishDate.Year.ToString()).OrderBy(group => group.Key); + GroupedBooks = Books.GroupBy(b => b.PublishDate.Year.ToString()).OrderBy(group => group.Key); } } OnPropertyChanged(nameof(GroupedBooks)); - OnPropertyChanged(nameof(AllBooks)); + OnPropertyChanged(nameof(Books)); } + [RelayCommand] private async Task GetAllPublishDates() { var result = await Model.GetBooksFromCollection(0, 1000); IEnumerable someBooks = result.books; - books.Clear(); - publishDates.Clear(); + Books.Clear(); + PublishDates.Clear(); foreach (var b in someBooks.Select(b => new BookVM(b))) { var date = new PublishDateVM { PublishDate = b.PublishDate }; date.NbBooksWritten++; - publishDates.Add(date); - foreach (var p in publishDates) + PublishDates.Add(date); + foreach (var p in PublishDates) { if (date.PublishDate.Year == p.PublishDate.Year && !date.Equals(p)) { p.NbBooksWritten++; - publishDates.Remove(date); + PublishDates.Remove(date); } } } - OnPropertyChanged(nameof(AllPublishDates)); + OnPropertyChanged(nameof(PublishDates)); } + [RelayCommand] private async Task GetBooksByRating() { var result = await Model.GetBooksFromCollection(0, 1000); NbBooks = result.count; IEnumerable someBooks = result.books; - books.Clear(); + Books.Clear(); var groupedBooks = someBooks .Where(book => book.UserRating.HasValue) @@ -595,17 +318,16 @@ namespace ViewModels GroupedBooks = groupedBooks; OnPropertyChanged(nameof(GroupedBooks)); - OnPropertyChanged(nameof(AllBooks)); + OnPropertyChanged(nameof(Books)); } - - + [RelayCommand] private async Task GetAllRatings() { var result = await Model.GetBooksFromCollection(0, 1000); IEnumerable someBooks = result.books; - books.Clear(); - ratings.Clear(); + Books.Clear(); + Ratings.Clear(); Dictionary> groupedBooks = new Dictionary>(); @@ -639,19 +361,21 @@ namespace ViewModels ratings.Add(rating); } - OnPropertyChanged(nameof(AllRatings)); + OnPropertyChanged(nameof(Ratings)); } + [RelayCommand] private async Task GetAllStatus() { var allStatusValues = Enum.GetValues(typeof(Status)).OfType(); foreach (var s in allStatusValues) { - status.Add(s); + allStatus.Add(s); } OnPropertyChanged(nameof(AllStatus)); } + [RelayCommand] private async Task GetToBeReadBooks() { var result = await Model.GetBooksFromCollection(0, 1000); @@ -668,6 +392,7 @@ namespace ViewModels OnPropertyChanged(nameof(ToBeReadBooks)); } + [RelayCommand] private async Task GetFavoriteBooks() { var result = await Model.GetFavoritesBooks(0, 1000); @@ -678,9 +403,10 @@ namespace ViewModels { favoriteBooks.Add(b); } - OnPropertyChanged(nameof(AllFavoriteBooks)); + OnPropertyChanged(nameof(FavoriteBooks)); } + [RelayCommand] private async Task AddToFavorites(BookVM bookVM) { var book = await Model.GetBookById(bookVM.Id); @@ -688,6 +414,7 @@ namespace ViewModels await GetFavoriteBooks(); } + [RelayCommand] private async Task RemoveFromFavorites(BookVM bookVM) { var book = await Model.GetBookById(bookVM.Id); @@ -695,10 +422,11 @@ namespace ViewModels await GetFavoriteBooks(); } + [RelayCommand] private async Task CheckBookIsFavorite(BookVM bookVM) { await GetFavoriteBooks(); - if (AllFavoriteBooks.Any(favoriteBook => favoriteBook.Id == bookVM.Id)) + if (FavoriteBooks.Any(favoriteBook => favoriteBook.Id == bookVM.Id)) { IsFavorite = true; OnPropertyChanged(nameof(IsFavorite)); @@ -710,6 +438,7 @@ namespace ViewModels } } + [RelayCommand] private async Task GetCurrentLoans() { var result = await Model.GetCurrentLoans(0, 1000); @@ -718,11 +447,12 @@ namespace ViewModels foreach (var l in someLoans.Select(l => new LoanVM(l))) { currentLoans.Add(l); - AllCurrentGroupedLoans = AllCurrentLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key); + CurrentGroupedLoans = CurrentLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key); } - OnPropertyChanged(nameof(AllCurrentLoans)); + OnPropertyChanged(nameof(CurrentLoans)); } + [RelayCommand] private async Task GetPastLoans() { var result = await Model.GetPastLoans(0, 1000); @@ -731,11 +461,12 @@ namespace ViewModels foreach (var l in someLoans.Select(l => new LoanVM(l))) { pastLoans.Add(l); - AllPastGroupedLoans = AllPastLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key); + PastGroupedLoans = PastLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key); } - OnPropertyChanged(nameof(AllPastLoans)); + OnPropertyChanged(nameof(PastLoans)); } + [RelayCommand] private async Task GetCurrentBorrowings() { var result = await Model.GetCurrentBorrowings(0, 1000); @@ -744,11 +475,12 @@ namespace ViewModels foreach (var b in someBorrowings.Select(b => new BorrowingVM(b))) { currentBorrowings.Add(b); - AllCurrentGroupedBorrowings = AllCurrentBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key); + CurrentGroupedBorrowings = CurrentBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key); } - OnPropertyChanged(nameof(AllCurrentBorrowings)); + OnPropertyChanged(nameof(CurrentBorrowings)); } + [RelayCommand] private async Task GetPastBorrowings() { var result = await Model.GetPastBorrowings(0, 1000); @@ -757,16 +489,17 @@ namespace ViewModels foreach (var b in someBorrowings.Select(b => new BorrowingVM(b))) { pastBorrowings.Add(b); - AllPastGroupedBorrowings = AllPastBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key); + PastGroupedBorrowings = PastBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key); } - OnPropertyChanged(nameof(AllPastBorrowings)); + OnPropertyChanged(nameof(PastBorrowings)); } + [RelayCommand] private async Task LendBook(ContactVM contactVM) { var book = await Model.GetBookById(SelectedBook.Id); Model.Contact contact = new Model.Contact(); - var resultContacts = await Model.GetContacts(Index, Count); + var resultContacts = await Model.GetContacts(IndexPage, Count); var allContacts = resultContacts.contacts; foreach (var c in allContacts) { @@ -781,9 +514,10 @@ namespace ViewModels } } + [RelayCommand] private async Task GetContacts() { - var result = await Model.GetContacts(Index, Count); + var result = await Model.GetContacts(IndexPage, Count); IEnumerable someContacts = result.contacts; someContacts = someContacts.OrderBy(c => c.FirstName); contacts.Clear(); @@ -791,12 +525,13 @@ namespace ViewModels { contacts.Add(c); } - OnPropertyChanged(nameof(AllContacts)); + OnPropertyChanged(nameof(Contacts)); } + [RelayCommand] private async Task AddContact() { - var result = await Model.GetContacts(Index, Count); + var result = await Model.GetContacts(IndexPage, Count); IEnumerable someContacts = result.contacts; int lastSequence = someContacts @@ -820,7 +555,7 @@ namespace ViewModels GivenLastName = null; await Model.AddContact(newContact); - OnPropertyChanged(nameof(AllContacts)); + OnPropertyChanged(nameof(Contacts)); } #endregion diff --git a/ViewModels/PublishDateVM.cs b/ViewModels/PublishDateVM.cs index cd16372..ea5e60f 100644 --- a/ViewModels/PublishDateVM.cs +++ b/ViewModels/PublishDateVM.cs @@ -1,4 +1,4 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; using System; using System.Collections.Generic; using System.Linq; @@ -7,13 +7,20 @@ using System.Threading.Tasks; namespace ViewModels { - public class PublishDateVM : BaseViewModel + [ObservableObject] + public partial class PublishDateVM { - #region Properties + #region Fields + + [ObservableProperty] + private DateTime publishDate; - public DateTime PublishDate { get; set; } + [ObservableProperty] + private int nbBooksWritten; - public int NbBooksWritten { get; set; } + #endregion + + #region Properties #endregion diff --git a/ViewModels/RatingsVM.cs b/ViewModels/RatingsVM.cs index fb22263..4db1bcc 100644 --- a/ViewModels/RatingsVM.cs +++ b/ViewModels/RatingsVM.cs @@ -1,5 +1,5 @@ -using Model; -using PersonalMVVMToolkit; +using CommunityToolkit.Mvvm.ComponentModel; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -8,28 +8,23 @@ using System.Threading.Tasks; namespace ViewModels { - public class RatingsVM + [ObservableObject] + public partial class RatingsVM { #region Fields - private int nbBooksWritten { get; set; } + [ObservableProperty] + private int nbBooksWritten; - #endregion - - #region Properties + [ObservableProperty] + private float? average; - public float? Average { get; set; } + [ObservableProperty] + private int count; - public int Count { get; set; } + #endregion - public int NbBooksWritten - { - get => nbBooksWritten; - set - { - nbBooksWritten = value; - } - } + #region Properties #endregion diff --git a/ViewModels/ViewModels.csproj b/ViewModels/ViewModels.csproj index e8a57a7..29b17ef 100644 --- a/ViewModels/ViewModels.csproj +++ b/ViewModels/ViewModels.csproj @@ -7,9 +7,13 @@ true + + + + + -