From ad5d0b50df6823caa5547f9050915d1d938dff84 Mon Sep 17 00:00:00 2001 From: lobroda Date: Sat, 7 Oct 2023 11:21:45 +0100 Subject: [PATCH] ADD : number books/author + filter by date --- LivreLand/LivreLand.csproj | 4 + LivreLand/MauiProgram.cs | 4 +- LivreLand/View/FiltrageAuteurView.xaml | 13 +-- LivreLand/View/FiltrageDateView.xaml | 115 ++++-------------------- LivreLand/View/FiltrageDateView.xaml.cs | 33 ++++++- LivreLand/ViewModel/FiltrageDateVM.cs | 31 +++++++ LivreLand/ViewModel/PublishDateVM.cs | 29 ++++++ ViewModels/AuthorVM.cs | 11 +++ ViewModels/ManagerVM.cs | 41 +++++++++ ViewModels/PublishDateVM.cs | 29 ++++++ 10 files changed, 202 insertions(+), 108 deletions(-) create mode 100644 LivreLand/ViewModel/FiltrageDateVM.cs create mode 100644 LivreLand/ViewModel/PublishDateVM.cs create mode 100644 ViewModels/PublishDateVM.cs diff --git a/LivreLand/LivreLand.csproj b/LivreLand/LivreLand.csproj index fc00edc..3081b24 100644 --- a/LivreLand/LivreLand.csproj +++ b/LivreLand/LivreLand.csproj @@ -48,6 +48,10 @@ + + + + diff --git a/LivreLand/MauiProgram.cs b/LivreLand/MauiProgram.cs index 106d7c2..8b4ea78 100644 --- a/LivreLand/MauiProgram.cs +++ b/LivreLand/MauiProgram.cs @@ -26,6 +26,7 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() @@ -36,7 +37,8 @@ public static class MauiProgram .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); #if DEBUG builder.Logging.AddDebug(); diff --git a/LivreLand/View/FiltrageAuteurView.xaml b/LivreLand/View/FiltrageAuteurView.xaml index d132381..5da8f01 100644 --- a/LivreLand/View/FiltrageAuteurView.xaml +++ b/LivreLand/View/FiltrageAuteurView.xaml @@ -35,15 +35,18 @@ - + + ButtonIcon="book.png" + ButtonNumber="{Binding NbBooksWritten}" + ButtonRedIconVisible="True" + ButtonBlackIconVisible="False"/> diff --git a/LivreLand/View/FiltrageDateView.xaml b/LivreLand/View/FiltrageDateView.xaml index 4cd31eb..a731aac 100644 --- a/LivreLand/View/FiltrageDateView.xaml +++ b/LivreLand/View/FiltrageDateView.xaml @@ -4,6 +4,7 @@ xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:view="clr-namespace:LivreLand.View" xmlns:contentView="clr-namespace:LivreLand.View.ContentViews" + xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels" x:Class="LivreLand.View.FiltrageDateView" Title="FiltrageDateView"> @@ -33,104 +34,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/LivreLand/View/FiltrageDateView.xaml.cs b/LivreLand/View/FiltrageDateView.xaml.cs index 97ff4b4..57694e9 100644 --- a/LivreLand/View/FiltrageDateView.xaml.cs +++ b/LivreLand/View/FiltrageDateView.xaml.cs @@ -1,9 +1,34 @@ +using LivreLand.ViewModel; + namespace LivreLand.View; public partial class FiltrageDateView : ContentPage { - public FiltrageDateView() - { - InitializeComponent(); - } + #region Properties + + public FiltrageDateVM FiltrageDateVM { get; set; } + + #endregion + + #region Constructor + + public FiltrageDateView(FiltrageDateVM filtrageDateVM) + { + FiltrageDateVM = filtrageDateVM; + InitializeComponent(); + BindingContext = this; + } + + #endregion + + #region Methods + + protected override void OnAppearing() + { + base.OnAppearing(); + + FiltrageDateVM.Manager.GetAllPublishDatesCommand.Execute(null); + } + + #endregion } \ No newline at end of file diff --git a/LivreLand/ViewModel/FiltrageDateVM.cs b/LivreLand/ViewModel/FiltrageDateVM.cs new file mode 100644 index 0000000..cdf7577 --- /dev/null +++ b/LivreLand/ViewModel/FiltrageDateVM.cs @@ -0,0 +1,31 @@ +using PersonalMVVMToolkit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ViewModels; + +namespace LivreLand.ViewModel +{ + public class FiltrageDateVM : BaseViewModel + { + #region Properties + + public NavigatorVM Navigator { get; private set; } + + public ManagerVM Manager { get; private set; } + + #endregion + + #region Constructor + + public FiltrageDateVM(NavigatorVM navigatorVM, ManagerVM managerVM) + { + Navigator = navigatorVM; + Manager = managerVM; + } + + #endregion + } +} diff --git a/LivreLand/ViewModel/PublishDateVM.cs b/LivreLand/ViewModel/PublishDateVM.cs new file mode 100644 index 0000000..6f2edde --- /dev/null +++ b/LivreLand/ViewModel/PublishDateVM.cs @@ -0,0 +1,29 @@ +using PersonalMVVMToolkit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LivreLand.ViewModel +{ + public class PublishDateVM : BaseViewModel + { + #region Properties + + public DateTime PublishDate { get; set; } + + public int NbBooksWritten { get; set; } + + #endregion + + #region Constructor + + public PublishDateVM() + { + + } + + #endregion + } +} diff --git a/ViewModels/AuthorVM.cs b/ViewModels/AuthorVM.cs index 8f6859d..8072008 100644 --- a/ViewModels/AuthorVM.cs +++ b/ViewModels/AuthorVM.cs @@ -13,6 +13,8 @@ namespace ViewModels #region Fields + private int nbBooksWritten { get; set; } + #endregion #region Properties @@ -26,6 +28,15 @@ namespace ViewModels } } + public int NbBooksWritten + { + get => nbBooksWritten; + set + { + nbBooksWritten = value; + } + } + #endregion #region Constructor diff --git a/ViewModels/ManagerVM.cs b/ViewModels/ManagerVM.cs index 54752f7..c492a9d 100644 --- a/ViewModels/ManagerVM.cs +++ b/ViewModels/ManagerVM.cs @@ -12,6 +12,7 @@ namespace ViewModels private readonly ObservableCollection books = new ObservableCollection(); private readonly ObservableCollection authors = new ObservableCollection(); + private readonly ObservableCollection publishDates = new ObservableCollection(); private int index; private long nbBooks; @@ -29,6 +30,13 @@ namespace ViewModels get => authors; } + public ObservableCollection AllPublishDates + { + get => publishDates; + } + + public AuthorVM SelectedAuthor { get; private set; } + public string SearchTitle { get; private set; } public int Index @@ -58,8 +66,12 @@ namespace ViewModels public ICommand GetBooksFromCollectionCommand { get; private set; } + public ICommand GetBooksByAuthorCommand { get; private set; } + public ICommand GetAllAuthorsCommand { get; private set; } + public ICommand GetAllPublishDatesCommand { get; private set; } + #endregion #region Constructor @@ -69,7 +81,9 @@ namespace ViewModels PreviousCommand = new RelayCommand(() => Previous()); NextCommand = new RelayCommand(() => Next()); GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection()); + GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor()); GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors()); + GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates()); //GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book))); } @@ -110,6 +124,19 @@ namespace ViewModels OnPropertyChanged(nameof(AllBooks)); } + private async Task GetBooksByAuthor() + { + var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, Index, Count); + NbBooks = result.count; + IEnumerable someBooks = result.books; + books.Clear(); + foreach (var b in someBooks.Select(b => new BookVM(b))) + { + books.Add(b); + } + OnPropertyChanged(nameof(AllBooks)); + } + private async Task GetAllAuthors() { var result = await Model.GetBooksFromCollection(0, 20); @@ -121,11 +148,25 @@ namespace ViewModels foreach (var a in b.Authors) { authors.Add(a); + a.NbBooksWritten++; } } OnPropertyChanged(nameof(AllAuthors)); } + private async Task GetAllPublishDates() + { + var result = await Model.GetBooksFromCollection(0, 20); + IEnumerable someBooks = result.books; + books.Clear(); + publishDates.Clear(); + foreach (var b in someBooks.Select(b => new BookVM(b))) + { + var date = new PublishDateVM { PublishDate = b.PublishDate }; + publishDates.Add(date); + } + OnPropertyChanged(nameof(AllPublishDates)); + } #endregion } } \ No newline at end of file diff --git a/ViewModels/PublishDateVM.cs b/ViewModels/PublishDateVM.cs new file mode 100644 index 0000000..cd16372 --- /dev/null +++ b/ViewModels/PublishDateVM.cs @@ -0,0 +1,29 @@ +using PersonalMVVMToolkit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ViewModels +{ + public class PublishDateVM : BaseViewModel + { + #region Properties + + public DateTime PublishDate { get; set; } + + public int NbBooksWritten { get; set; } + + #endregion + + #region Constructor + + public PublishDateVM() + { + + } + + #endregion + } +}