diff --git a/sources/PocketBook/Applicative_VM/ScanMenuVM.cs b/sources/PocketBook/Applicative_VM/ScanMenuVM.cs index 15b1e0e..9a1c954 100644 --- a/sources/PocketBook/Applicative_VM/ScanMenuVM.cs +++ b/sources/PocketBook/Applicative_VM/ScanMenuVM.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Windows.Input; using MyToolkitMVVM; +using ViewModel; namespace PocketBook.Applicative_VM { @@ -11,6 +12,7 @@ namespace PocketBook.Applicative_VM { public ICommand ShowScanMenu { get; private set; } public ICommand ModalISBN { get; private set; } + public ManagerVM Manager { get; private set; } private bool scanMenuIsVisible; @@ -20,15 +22,19 @@ namespace PocketBook.Applicative_VM set => SetProperty(ref scanMenuIsVisible,value); } - public ScanMenuVM() + public ScanMenuVM(ManagerVM manager) { + Manager = manager; ShowScanMenu = new Command(() => { ScanMenuIsVisible = !ScanMenuIsVisible; }); ModalISBN = new Command( - async () => await App.Current.MainPage.DisplayPromptAsync("Ajout d'un livre par ISBN", "Entrez l'ISBN présent sur votre livre pour l'ajouter à votre librarie") - ); + async () => { + string isbn = await App.Current.MainPage.DisplayPromptAsync("Ajout d'un livre par ISBN", "Entrez l'ISBN présent sur votre livre pour l'ajouter à votre librarie"); + if (isbn != null) { Manager.AddBookByISBN(isbn); } + } + ); ; } } } diff --git a/sources/ViewModel/ManagerVM.cs b/sources/ViewModel/ManagerVM.cs index 7a2de13..7d25e93 100644 --- a/sources/ViewModel/ManagerVM.cs +++ b/sources/ViewModel/ManagerVM.cs @@ -83,8 +83,10 @@ public class ManagerVM : BaseViewModel { OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedLaterBooks)); + OnPropertyChanged(nameof(Books)); + OnPropertyChanged(nameof(books)); //NbBookLater=books.Where(book => book.BookStatus == Status.ToBeRead).Count(); - Debug.WriteLine(NbBookLater); + //Debug.WriteLine(NbBookLater); } public ManagerVM(Manager model) : base(model) @@ -93,6 +95,19 @@ public class ManagerVM : BaseViewModel Books = new ReadOnlyObservableCollection(books); } + public void AddBookByISBN(string isbn) + { + var result= Model.GetBookByISBN(isbn).Result; + if (result != null) { + Debug.WriteLine(result.ToString()); + //books.Add(new BookVM(result)); + Model.AddBookToCollection(result.Id); + LoadBooksFromManager(); + Refresh(); + } + } + + public int Index { get => index;