diff --git a/LivreLand/View/ContactsView.xaml b/LivreLand/View/ContactsView.xaml index a9d53e4..446acd5 100644 --- a/LivreLand/View/ContactsView.xaml +++ b/LivreLand/View/ContactsView.xaml @@ -71,7 +71,7 @@ diff --git a/LivreLand/View/DetailsLivreView.xaml b/LivreLand/View/DetailsLivreView.xaml index 78a944b..132be4e 100644 --- a/LivreLand/View/DetailsLivreView.xaml +++ b/LivreLand/View/DetailsLivreView.xaml @@ -310,7 +310,7 @@ @@ -322,7 +322,7 @@ @@ -341,7 +341,7 @@ diff --git a/LivreLand/ViewModel/ContactsVM.cs b/LivreLand/ViewModel/ContactsVM.cs index 3e76581..85ea91c 100644 --- a/LivreLand/ViewModel/ContactsVM.cs +++ b/LivreLand/ViewModel/ContactsVM.cs @@ -1,4 +1,5 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Maui.Alerts; +using PersonalMVVMToolkit; using System; using System.Collections.Generic; using System.Linq; @@ -38,6 +39,8 @@ namespace LivreLand.ViewModel public ICommand AddContactDataFormCommand { get; private set; } + public ICommand BookLendedCommand { get; private set; } + #endregion #region Constructor @@ -47,6 +50,7 @@ namespace LivreLand.ViewModel Navigator = navigatorVM; Manager = managerVM; AddContactDataFormCommand = new RelayCommand(() => AddContactDataForm()); + BookLendedCommand = new RelayCommand((contactVM) => BookLended(contactVM)); } #endregion @@ -58,6 +62,16 @@ namespace LivreLand.ViewModel DataFormIsVisible = true; } + private async Task BookLended(ContactVM contactVM) + { + Manager.LendBookCommand.Execute(contactVM); + + var toast = Toast.Make("Livre prêté !", CommunityToolkit.Maui.Core.ToastDuration.Short); + await toast.Show(); + + Navigator.PopupBackButtonNavigationCommand.Execute(null); + } + #endregion } } diff --git a/LivreLand/ViewModel/DetailsLivreVM.cs b/LivreLand/ViewModel/DetailsLivreVM.cs index 36a7fa0..64ec30a 100644 --- a/LivreLand/ViewModel/DetailsLivreVM.cs +++ b/LivreLand/ViewModel/DetailsLivreVM.cs @@ -1,4 +1,5 @@ -using PersonalMVVMToolkit; +using CommunityToolkit.Maui.Alerts; +using PersonalMVVMToolkit; using System; using System.Collections.Generic; using System.Linq; @@ -40,6 +41,12 @@ namespace LivreLand.ViewModel public ICommand ShowPickerCommand { get; private set; } + public ICommand AddBookToFavoritesCommand { get; private set; } + + public ICommand AddBookToReadListCommand { get; private set; } + + public ICommand RemoveBookCommand { get; private set; } + #endregion #region Constructor @@ -50,6 +57,9 @@ namespace LivreLand.ViewModel Navigator = navigatorVM; Book = bookVM; ShowPickerCommand = new RelayCommand(() => ShowPicker()); + AddBookToFavoritesCommand = new RelayCommand((bookVM) => AddBookToFavorites(bookVM)); + AddBookToReadListCommand = new RelayCommand((bookVM) => AddBookToReadList(bookVM)); + RemoveBookCommand = new RelayCommand((bookVM) => RemoveBook(bookVM)); } #endregion @@ -61,6 +71,36 @@ namespace LivreLand.ViewModel IsPickerVisible = true; } + private async Task AddBookToFavorites(BookVM bookVM) + { + Manager.AddToFavoritesCommand.Execute(bookVM); + + var toast = Toast.Make("Livre ajouté aux favoris !", CommunityToolkit.Maui.Core.ToastDuration.Short); + await toast.Show(); + + Navigator.NavigationCommand.Execute("/favoris"); + } + + private async Task AddBookToReadList(BookVM bookVM) + { + Manager.UpdateToBeReadBookCommand.Execute(bookVM); + + var toast = Toast.Make("Livre ajouté à la liste À lire plus tard !", CommunityToolkit.Maui.Core.ToastDuration.Short); + await toast.Show(); + + Navigator.NavigationCommand.Execute("/later"); + } + + private async Task RemoveBook(BookVM bookVM) + { + Manager.RemoveBookCommand.Execute(bookVM); + + var toast = Toast.Make("Livre supprimé !", CommunityToolkit.Maui.Core.ToastDuration.Short); + await toast.Show(); + + Navigator.PopupBackButtonNavigationCommand.Execute(null); + } + #endregion } }