ADD : Avancement changement livre à lire (bug author books, lend book ToDo)

commands-19-09
Lou BRODA 1 year ago
parent 5ef7f9f9d8
commit 4664a2e79f

@ -4,6 +4,7 @@
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:view="clr-namespace:LivreLand.View" xmlns:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews" xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.DetailsLivreView" x:Class="LivreLand.View.DetailsLivreView"
Title="DetailsLivreView"> Title="DetailsLivreView">
<Grid> <Grid>
@ -112,9 +113,20 @@
<Label Text="Auteur" <Label Text="Auteur"
Style="{StaticResource DetailsLivreTitle}" Style="{StaticResource DetailsLivreTitle}"
Grid.Row="0"/> Grid.Row="0"/>
<Label Text="{Binding DetailsLivreVM.Book.Author}" <CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Authors}"
Style="{StaticResource DetailsLivreBody}" Grid.Row="1">
Grid.Row="1"/> <CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:AuthorVM">
<Label Text="{Binding Name}"
Style="{StaticResource DetailsLivreBody}"
Margin="0,0,5,0"
Grid.Row="1"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid> </Grid>
<contentView:SeparatorCutStartView/> <contentView:SeparatorCutStartView/>
@ -125,18 +137,32 @@
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Label Text="Maison d'édition" <Label Text="Maison d'édition"
Style="{StaticResource DetailsLivreTitle}" Style="{StaticResource DetailsLivreTitle}"
Grid.Row="0"/> Grid.Row="0"
<Label> Grid.Column="0"/>
<Label.FormattedText> <Grid Grid.Row="1"
<FormattedString> Grid.Column="1">
<Span Text="Gallimard"/> <CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Publishers}">
<Span Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat='({0})'}"/> <CollectionView.ItemsLayout>
</FormattedString> <LinearItemsLayout Orientation="Horizontal" />
</Label.FormattedText> </CollectionView.ItemsLayout>
</Label> <CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="oui"
Style="{StaticResource DetailsLivreBody}"
Margin="0,0,5,0"
Grid.Row="1"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Label Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat=' ({0:yyyy})'}"/>
</Grid>
</Grid> </Grid>
<contentView:SeparatorCutStartView/> <contentView:SeparatorCutStartView/>
@ -291,12 +317,15 @@
<contentView:SeparatorCutStartView/> <contentView:SeparatorCutStartView/>
<contentView:DetailsLivreButtonView ButtonIcon="rounded_plus" <contentView:DetailsLivreButtonView ButtonIcon="rounded_plus"
ButtonTitle="Ajouter à la liste À lire plus tard"/> ButtonTitle="Ajouter à la liste À lire plus tard"
ButtonCommand="{Binding DetailsLivreVM.Manager.UpdateToBeReadBookCommand}"
ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>
<contentView:SeparatorCutStartView/> <contentView:SeparatorCutStartView/>
<contentView:DetailsLivreButtonView ButtonIcon="eyeglasses.png" <contentView:DetailsLivreButtonView ButtonIcon="eyeglasses.png"
ButtonTitle="Changer le statut de lecture"/> ButtonTitle="Changer le statut de lecture"
ButtonCommand="{Binding DetailsLivreVM.Manager.UpdateStatusBookCommand}"/>
<contentView:SeparatorCutStartView/> <contentView:SeparatorCutStartView/>

@ -38,8 +38,7 @@
<CollectionView ItemsSource="{Binding FiltrageAuteurVM.Manager.AllAuthors}" <CollectionView ItemsSource="{Binding FiltrageAuteurVM.Manager.AllAuthors}"
SelectionMode="Single" SelectionMode="Single"
SelectedItem="{Binding FiltrageAuteurVM.Manager.SelectedAuthor}" SelectedItem="{Binding FiltrageAuteurVM.Manager.SelectedAuthor}"
SelectionChangedCommand="{Binding FiltrageAuteurVM.Navigator.NavigationCommand}" SelectionChangedCommand="{Binding FiltrageAuteurVM.NavigateAuthorPageCommand}">
SelectionChangedCommandParameter="/tous">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:AuthorVM"> <DataTemplate x:DataType="viewModel:AuthorVM">
<VerticalStackLayout> <VerticalStackLayout>

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels; using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
@ -16,6 +17,8 @@ namespace LivreLand.ViewModel
public ManagerVM Manager { get; private set; } public ManagerVM Manager { get; private set; }
public ICommand NavigateAuthorPageCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -24,6 +27,17 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
NavigateAuthorPageCommand = new RelayCommand(() => NavigateAuthorPage());
}
#endregion
#region Methods
private async Task NavigateAuthorPage()
{
Manager.GetBooksByAuthorCommand.Execute(null);
Navigator.NavigationCommand.Execute("/tous");
} }
#endregion #endregion

@ -64,6 +64,11 @@ namespace Model
return UserLibraryManager.UpdateBook(book); return UserLibraryManager.UpdateBook(book);
} }
public Task<bool> RemoveBook(Book book)
{
return UserLibraryManager.RemoveBook(book);
}
public Task<(long count, IEnumerable<Book> books)> GetBooksFromCollection(int index, int count, string sort = "") public Task<(long count, IEnumerable<Book> books)> GetBooksFromCollection(int index, int count, string sort = "")
{ {
var result = UserLibraryManager.GetBooksFromCollection(index, count, sort).Result; var result = UserLibraryManager.GetBooksFromCollection(index, count, sort).Result;
@ -115,5 +120,10 @@ namespace Model
var result = UserLibraryManager.GetPastBorrowings(index, count).Result; var result = UserLibraryManager.GetPastBorrowings(index, count).Result;
return Task.FromResult((result.Item1, result.Item2)); return Task.FromResult((result.Item1, result.Item2));
} }
public Task<bool> LendBook(Book book, Contact contact, DateTime? loanDate)
{
return UserLibraryManager.LendBook(book, contact, loanDate);
}
} }
} }

@ -84,6 +84,8 @@ namespace ViewModels
public RatingsVM SelectedRating { get; private set; } public RatingsVM SelectedRating { get; private set; }
public Status SelectedStatus { get; private set; }
public string SearchTitle { get; private set; } public string SearchTitle { get; private set; }
public int Index public int Index
@ -113,6 +115,14 @@ namespace ViewModels
public ICommand GetBooksFromCollectionCommand { get; private set; } public ICommand GetBooksFromCollectionCommand { 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 GetBooksByAuthorCommand { get; private set; }
public ICommand GetAllAuthorsCommand { get; private set; } public ICommand GetAllAuthorsCommand { get; private set; }
@ -129,6 +139,8 @@ namespace ViewModels
public ICommand AddToFavoritesCommand { get; private set; } public ICommand AddToFavoritesCommand { get; private set; }
public ICommand RemoveFromFavoritesCommand { get; private set; }
public ICommand GetCurrentLoansCommand { get; private set; } public ICommand GetCurrentLoansCommand { get; private set; }
public ICommand GetPastLoansCommand { get; private set; } public ICommand GetPastLoansCommand { get; private set; }
@ -148,6 +160,10 @@ namespace ViewModels
PreviousCommand = new RelayCommand(() => Previous()); PreviousCommand = new RelayCommand(() => Previous());
NextCommand = new RelayCommand(() => Next()); NextCommand = new RelayCommand(() => Next());
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection()); GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
UpdateBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateBook(bookVM));
UpdateStatusBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateStatusBook(bookVM));
UpdateToBeReadBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateToBeReadBook(bookVM));
RemoveBookCommand = new RelayCommand<BookVM>((bookVM) => RemoveBook(bookVM));
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor()); GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors()); GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate()); GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate());
@ -157,6 +173,7 @@ namespace ViewModels
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks()); GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
GetFavoriteBooksCommand = new RelayCommand(() => GetFavoriteBooks()); GetFavoriteBooksCommand = new RelayCommand(() => GetFavoriteBooks());
AddToFavoritesCommand = new RelayCommand<BookVM>(bookVM => AddToFavorites(bookVM)); AddToFavoritesCommand = new RelayCommand<BookVM>(bookVM => AddToFavorites(bookVM));
RemoveFromFavoritesCommand = new RelayCommand<BookVM>(bookVM => RemoveFromFavorites(bookVM));
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans()); GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
GetPastLoansCommand = new RelayCommand(() => GetPastLoans()); GetPastLoansCommand = new RelayCommand(() => GetPastLoans());
GetCurrentBorrowingsCommand = new RelayCommand(() => GetCurrentBorrowings()); GetCurrentBorrowingsCommand = new RelayCommand(() => GetCurrentBorrowings());
@ -202,6 +219,32 @@ namespace ViewModels
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(AllBooks));
} }
private async Task UpdateBook(BookVM bookVM)
{
var book = await Model.GetBookById(bookVM.Id);
await Model.UpdateBook(book);
}
private async Task UpdateStatusBook(BookVM bookVM)
{
var book = await Model.GetBookById(bookVM.Id);
book.Status = SelectedStatus;
await Model.UpdateBook(book);
}
private async Task UpdateToBeReadBook(BookVM bookVM)
{
var book = await Model.GetBookById(bookVM.Id);
book.Status = Status.ToBeRead;
await Model.UpdateBook(book);
}
private async Task RemoveBook(BookVM bookVM)
{
var book = await Model.GetBookById(bookVM.Id);
await Model.RemoveBook(book);
}
private async Task GetBooksByAuthor() private async Task GetBooksByAuthor()
{ {
var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, Index, Count); var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, Index, Count);
@ -363,6 +406,13 @@ namespace ViewModels
await GetFavoriteBooks(); await GetFavoriteBooks();
} }
private async Task RemoveFromFavorites(BookVM bookVM)
{
var book = await Model.GetBookById(bookVM.Id);
await Model.RemoveFromFavorites(book.Id);
await GetFavoriteBooks();
}
private async Task GetCurrentLoans() private async Task GetCurrentLoans()
{ {
var result = await Model.GetCurrentLoans(0, 20); var result = await Model.GetCurrentLoans(0, 20);
@ -411,6 +461,11 @@ namespace ViewModels
OnPropertyChanged(nameof(AllPastBorrowings)); OnPropertyChanged(nameof(AllPastBorrowings));
} }
//private async Task LendBook()
//{
// await Model.LendBook();
//}
#endregion #endregion
} }
} }
Loading…
Cancel
Save