Gestion de la suppresion de livres

master
Lucas Evard 2 years ago
parent e61ca0ad36
commit c2f133206b

@ -57,7 +57,12 @@ namespace Model
return UserLibraryManager.AddBook(id); return UserLibraryManager.AddBook(id);
} }
public async Task<Book> GetBookByIdFromCollection(string id) public Task<bool> RemoveBookToCollection(Book book)
{
return UserLibraryManager.RemoveBook(book);
}
public async Task<Book> GetBookByIdFromCollection(string id)
=> await UserLibraryManager.GetBookById(id); => await UserLibraryManager.GetBookById(id);

@ -13,6 +13,7 @@ namespace PocketBook.Applicative_VM
public ICommand ShowScanMenu { get; private set; } public ICommand ShowScanMenu { get; private set; }
public ICommand ModalISBN { get; private set; } public ICommand ModalISBN { get; private set; }
public ManagerVM Manager { get; private set; } public ManagerVM Manager { get; private set; }
public PaginationVM PaginationVM { get; private set; }
private bool scanMenuIsVisible; private bool scanMenuIsVisible;
@ -22,9 +23,10 @@ namespace PocketBook.Applicative_VM
set => SetProperty(ref scanMenuIsVisible,value); set => SetProperty(ref scanMenuIsVisible,value);
} }
public ButtonsVM(ManagerVM manager) public ButtonsVM(ManagerVM manager, PaginationVM paginationVM)
{ {
Manager = manager; Manager = manager;
PaginationVM = paginationVM;
ShowScanMenu = new Command(() => ShowScanMenu = new Command(() =>
{ {
ScanMenuIsVisible = !ScanMenuIsVisible; ScanMenuIsVisible = !ScanMenuIsVisible;
@ -32,7 +34,13 @@ namespace PocketBook.Applicative_VM
ModalISBN = new Command( ModalISBN = new Command(
async () => { 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"); 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); } if (isbn != null) {
Manager.AddBookByISBN(isbn);
((Command)PaginationVM.NormalIncreasePage).ChangeCanExecute();
((Command)PaginationVM.NormalDecreasePage).ChangeCanExecute();
((Command)PaginationVM.LaterIncreasePage).ChangeCanExecute();
((Command)PaginationVM.LaterDecreasePage).ChangeCanExecute();
}
} }
); ; ); ;
} }

@ -9,12 +9,16 @@ namespace PocketBook.Applicative_VM
public class DetailPageVM : BaseViewModel public class DetailPageVM : BaseViewModel
{ {
public ManagerVM Manager { get; private set; } public ManagerVM Manager { get; private set; }
public ICommand ChangeStatus { get; private set; } public PaginationVM PaginationVM { get; private set; }
public ICommand ChangeStatus { get; private set; }
public ICommand AddReadLaterList { get; private set; } public ICommand AddReadLaterList { get; private set; }
public ICommand MoveBook { get; private set; }
public DetailPageVM(ManagerVM manager) public DetailPageVM(ManagerVM manager, PaginationVM paginationVM)
{ {
Manager = manager; Manager = manager;
PaginationVM = paginationVM;
ChangeStatus = new Command(async o => ChangeStatus = new Command(async o =>
{ {
@ -28,7 +32,17 @@ namespace PocketBook.Applicative_VM
Manager.ChangeStatut("À lire"); Manager.ChangeStatut("À lire");
_ = Toast.Make("Ajout dans la liste de livre à lire plus tard", ToastDuration.Short, 14).Show(new CancellationTokenSource().Token); _ = Toast.Make("Ajout dans la liste de livre à lire plus tard", ToastDuration.Short, 14).Show(new CancellationTokenSource().Token);
}); });
MoveBook = new Command(async o =>
{
string action = await App.Current.MainPage.DisplayActionSheet("Selectionne où tu veux déplacer ce livre", "Retour", "Mettre à la poubelle", "Déplacer en favoris");
Manager.MoveBook(action);
_ = Toast.Make("Déplacement du livre en => " + action, ToastDuration.Short, 14).Show(new CancellationTokenSource().Token);
((Command)PaginationVM.NormalIncreasePage).ChangeCanExecute();
((Command)PaginationVM.NormalDecreasePage).ChangeCanExecute();
((Command)PaginationVM.LaterIncreasePage).ChangeCanExecute();
((Command)PaginationVM.LaterDecreasePage).ChangeCanExecute();
await App.Current.MainPage.Navigation.PopAsync();
});
} }
} }
} }

@ -24,7 +24,7 @@ namespace PocketBook.Applicative_VM
((Command)NormalDecreasePage).ChangeCanExecute(); ((Command)NormalDecreasePage).ChangeCanExecute();
}, },
canExecute: () => { canExecute: () => {
return Manager.NbBook / 5 > Manager.Index; return Manager.NbBook / Manager.NBLIVREPARPAGE > Manager.Index;
}); });
NormalDecreasePage = new Command(execute:() => NormalDecreasePage = new Command(execute:() =>
@ -43,17 +43,17 @@ namespace PocketBook.Applicative_VM
LaterIncreasePage = new Command(execute: () => LaterIncreasePage = new Command(execute: () =>
{ {
if(Manager.NbBookLater / 5 > Manager.IndexLater) { Manager.IndexLater++;
Manager.IndexLater++; Manager.LoadBooksFromManager();
Manager.LoadBooksFromManager(); ((Command)LaterIncreasePage).ChangeCanExecute();
((Command)LaterIncreasePage).ChangeCanExecute(); ((Command)LaterDecreasePage).ChangeCanExecute();
((Command)LaterDecreasePage).ChangeCanExecute();
}
}, },
canExecute: () => canExecute: () =>
{ {
return Manager.NbBookLater / 5 > Manager.IndexLater; return Manager.NbBookLater / Manager.NBLIVREPARPAGE > Manager.IndexLater;
}); });
LaterDecreasePage = new Command(execute: () => LaterDecreasePage = new Command(execute: () =>
{ {
Manager.IndexLater--; Manager.IndexLater--;

@ -23,8 +23,6 @@ namespace PocketBook.Applicative_VM
Manager = manager; Manager = manager;
PaginationVM = paginationVM; PaginationVM = paginationVM;
NavigateCommandBooks = navigation; NavigateCommandBooks = navigation;
//Manager.LoadBooksFromManager();
NavigateDetailPage = new Command<BookVM>(book => NavigateDetailPage = new Command<BookVM>(book =>
{ {
Manager.SelectedBook = book; Manager.SelectedBook = book;

@ -81,7 +81,7 @@
<Line BackgroundColor="{StaticResource LineColor1}"/> <Line BackgroundColor="{StaticResource LineColor1}"/>
<StackLayout Padding="50"/> <StackLayout Padding="50"/>
<Line BackgroundColor="{StaticResource LineColor1}"/> <Line BackgroundColor="{StaticResource LineColor1}"/>
<local:BookChange PropertyName="Déplacer le livre" ImageName="folder.png"/> <local:BookChange Command="{Binding MoveBook}" PropertyName="Déplacer le livre" ImageName="folder.png"/>
<Line BackgroundColor="{StaticResource LineColor1}"/> <Line BackgroundColor="{StaticResource LineColor1}"/>
<local:BookChange Command="{Binding AddReadLaterList}" PropertyName="Ajouter à la liste à lire plus tard" ImageName="plus_round.png"/> <local:BookChange Command="{Binding AddReadLaterList}" PropertyName="Ajouter à la liste à lire plus tard" ImageName="plus_round.png"/>
<Line BackgroundColor="{StaticResource LineColor1}"/> <Line BackgroundColor="{StaticResource LineColor1}"/>

@ -37,7 +37,6 @@
<local:ContentViewFilter Command="{Binding TousPageVM.NavigateAndLoadData}" FilterImageName="tray_second_fill.png" FilterName="Tous" FilterNum="45"/> <local:ContentViewFilter Command="{Binding TousPageVM.NavigateAndLoadData}" FilterImageName="tray_second_fill.png" FilterName="Tous" FilterNum="45"/>
<Line Style="{StaticResource LineStyle2}"/> <Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="SharePage" FilterImageName="person_badge_clock_fill.png" FilterName="En prêt" FilterNum="1"/> <local:ContentViewFilter Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="SharePage" FilterImageName="person_badge_clock_fill.png" FilterName="En prêt" FilterNum="1"/>

@ -1,13 +1,14 @@
namespace ViewModel; namespace ViewModel;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using Model; using Model;
using MyToolkitMVVM; using MyToolkitMVVM;
using static System.Runtime.InteropServices.JavaScript.JSType;
public class ManagerVM : BaseViewModel<Manager> public class ManagerVM : BaseViewModel<Manager>
{ {
public int NBLIVREPARPAGE = 6;
public ReadOnlyObservableCollection<BookVM> Books { get; set; } public ReadOnlyObservableCollection<BookVM> Books { get; set; }
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>(); private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
public RelayCommand<string> LoadBooks { get; private set; } public RelayCommand<string> LoadBooks { get; private set; }
@ -30,7 +31,7 @@ public class ManagerVM : BaseViewModel<Manager>
public async void LoadBooksFromManager() public async void LoadBooksFromManager()
{ {
var result = await Model.GetBooksFromCollection(index, 5, ""); var result = await Model.GetBooksFromCollection(index, NBLIVREPARPAGE, "");
NbBook = (int)result.count; NbBook = (int)result.count;
books.Clear(); books.Clear();
@ -43,7 +44,7 @@ public class ManagerVM : BaseViewModel<Manager>
public async void LoadBooksReadLaterFromManager() public async void LoadBooksReadLaterFromManager()
{ {
var result = await Model.GetBooksFromCollection(indexLater, 5, ""); var result = await Model.GetBooksFromCollection(indexLater, NBLIVREPARPAGE, "");
books.Clear(); books.Clear();
nbBookLater = 0; nbBookLater = 0;
foreach (Book book in result.books) foreach (Book book in result.books)
@ -74,7 +75,7 @@ public class ManagerVM : BaseViewModel<Manager>
{ {
filters.Add(date); filters.Add(date);
} }
OnPropertyChanged(nameof(filters)); Refresh();
} }
public async Task GetAuthorFromCollection() public async Task GetAuthorFromCollection()
@ -94,7 +95,7 @@ public class ManagerVM : BaseViewModel<Manager>
{ {
filters.Add(author); filters.Add(author);
} }
OnPropertyChanged(nameof(filters)); Refresh();
} }
public async Task GetMarkFromCollection() public async Task GetMarkFromCollection()
@ -113,7 +114,7 @@ public class ManagerVM : BaseViewModel<Manager>
{ {
filters.Add(mark); filters.Add(mark);
} }
OnPropertyChanged(nameof(filters)); Refresh();
} }
public async Task GetBooksFromAuthor(string author) public async Task GetBooksFromAuthor(string author)
@ -185,6 +186,8 @@ public class ManagerVM : BaseViewModel<Manager>
{ {
OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedBooks));
OnPropertyChanged(nameof(GroupedLaterBooks)); OnPropertyChanged(nameof(GroupedLaterBooks));
OnPropertyChanged(nameof(filters));
OnPropertyChanged(nameof(books));
} }
public ManagerVM(Manager model) : base(model) public ManagerVM(Manager model) : base(model)
@ -204,6 +207,26 @@ public class ManagerVM : BaseViewModel<Manager>
} }
} }
public async void RemoveSelectedBookToCollection()
{
var result= await Model.GetBookById(SelectedBook.Id);
NbBook--;
await Model.RemoveBookToCollection(result);
books.Remove(SelectedBook);
Refresh();
}
public void MoveBook(string action)
{
switch (action)
{
case "Mettre à la poubelle":
RemoveSelectedBookToCollection();
break;
case "Déplacer en favoris":
break;
}
}
public int Index public int Index
{ {

Loading…
Cancel
Save