ADD : base added - compiling but not working yet

TP3
Lou BRODA 1 year ago
parent bb53472775
commit 13e5cb95d8

@ -6,6 +6,11 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\LibraryDTO\LibraryDTO.csproj" /> <ProjectReference Include="..\LibraryDTO\LibraryDTO.csproj" />
</ItemGroup> </ItemGroup>

@ -7,6 +7,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>

@ -6,4 +6,9 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
</Project> </Project>

@ -54,13 +54,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Camera.MAUI" Version="1.4.4" /> <PackageReference Include="Camera.MAUI" Version="1.4.4" />
<PackageReference Include="CommunityToolkit.Maui" Version="5.3.0" /> <PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\PersonalMVVMToolkit\PersonalMVVMToolkit.csproj" />
<ProjectReference Include="..\Stub\Stub.csproj" /> <ProjectReference Include="..\Stub\Stub.csproj" />
<ProjectReference Include="..\ViewModels\ViewModels.csproj" /> <ProjectReference Include="..\ViewModels\ViewModels.csproj" />
</ItemGroup> </ItemGroup>

@ -32,7 +32,7 @@
EmpruntsButtonCommand="{Binding EmpruntsPretsVM.EmpruntsButtonCommand}"/> EmpruntsButtonCommand="{Binding EmpruntsPretsVM.EmpruntsButtonCommand}"/>
<ScrollView Grid.Row="4"> <ScrollView Grid.Row="4">
<Grid> <Grid>
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentGroupedLoans}" <CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.CurrentGroupedLoans}"
SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedLoan}" SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedLoan}"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionLoanChangedCommand}" SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionLoanChangedCommand}"
@ -133,7 +133,7 @@
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentGroupedBorrowings}" <CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.CurrentGroupedBorrowings}"
SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}" SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionBorrowingChangedCommand}" SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionBorrowingChangedCommand}"

@ -41,7 +41,7 @@
Style="{StaticResource HeaderCollectionViewText}" Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/> Grid.Column="1"/>
</Grid> </Grid>
<CollectionView ItemsSource="{Binding FavorisVM.Manager.AllFavoriteBooks}" <CollectionView ItemsSource="{Binding FavorisVM.Manager.FavoriteBooks}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChanged="OnSelectionChanged"
Grid.Row="2"> Grid.Row="2">

@ -165,7 +165,7 @@
Grid.Column="3"> Grid.Column="3">
<Label.FormattedText> <Label.FormattedText>
<FormattedString> <FormattedString>
<Span Text="{Binding TousVM.Manager.Index}"/> <Span Text="{Binding TousVM.Manager.IndexPage}"/>
<Span Text="/"/> <Span Text="/"/>
<Span Text="{Binding TousVM.Manager.NbPages}"/> <Span Text="{Binding TousVM.Manager.NbPages}"/>
</FormattedString> </FormattedString>

@ -1,5 +1,6 @@
using LivreLand.View; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,15 +11,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class ALirePlusTardVM : BaseViewModel [ObservableObject]
public partial class ALirePlusTardVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand OnSelectionChangedCommand { get; private set; } #region Properties
#endregion #endregion
@ -28,13 +34,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void OnSelectionChanged(BookVM bookVM) private void OnSelectionChanged(BookVM bookVM)
{ {
if (bookVM != null) if (bookVM != null)

@ -1,4 +1,5 @@
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,29 +10,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class BibliothequeVM : BaseViewModel [ObservableObject]
public partial class BibliothequeVM
{ {
#region Properties #region Fields
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
public ICommand AllBooksNavigateCommand { get; private set; }
public ICommand AllLoansBorrowingsNavigateCommand { get; private set; }
public ICommand AllFavorisBooksNavigateCommand { get; private set; } [ObservableProperty]
private NavigatorVM navigator;
public ICommand AllStatusBooksNavigateCommand { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ICommand AllToReadBooksNavigateCommand { get; private set; } #endregion
public ICommand AllAuthorsNavigateCommand { get; private set; }
public ICommand AllDatesNavigateCommand { get; private set; }
public ICommand AllRatingsNavigateCommand { get; private set; } #region Properties
#endregion #endregion
@ -41,26 +33,20 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
AllBooksNavigateCommand = new RelayCommand(() => AllBooksNavigate());
AllLoansBorrowingsNavigateCommand = new RelayCommand(() => AllLoansBorrowingsNavigate());
AllFavorisBooksNavigateCommand = new RelayCommand(() => AllFavorisBooksNavigate());
AllStatusBooksNavigateCommand = new RelayCommand(() => AllStatusBooksNavigate());
AllToReadBooksNavigateCommand = new RelayCommand(() => AllToReadBooksNavigate());
AllAuthorsNavigateCommand = new RelayCommand(() => AllAuthorsNavigate());
AllDatesNavigateCommand = new RelayCommand(() => AllDatesNavigate());
AllRatingsNavigateCommand = new RelayCommand(() => AllRatingsNavigate());
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void AllBooksNavigate() private void AllBooksNavigate()
{ {
Manager.GetBooksFromCollectionCommand.Execute(null); Manager.GetBooksFromCollectionCommand.Execute(null);
Navigator.NavigationCommand.Execute("/tous"); Navigator.NavigationCommand.Execute("/tous");
} }
[RelayCommand]
private void AllLoansBorrowingsNavigate() private void AllLoansBorrowingsNavigate()
{ {
Manager.GetCurrentLoansCommand.Execute(null); Manager.GetCurrentLoansCommand.Execute(null);
@ -68,36 +54,42 @@ namespace LivreLand.ViewModel
Navigator.NavigationCommand.Execute("/pret"); Navigator.NavigationCommand.Execute("/pret");
} }
[RelayCommand]
private void AllFavorisBooksNavigate() private void AllFavorisBooksNavigate()
{ {
Manager.GetFavoriteBooksCommand.Execute(null); Manager.GetFavoriteBooksCommand.Execute(null);
Navigator.NavigationCommand.Execute("/favoris"); Navigator.NavigationCommand.Execute("/favoris");
} }
[RelayCommand]
private void AllStatusBooksNavigate() private void AllStatusBooksNavigate()
{ {
Manager.GetBooksFromCollectionCommand.Execute(null); Manager.GetBooksFromCollectionCommand.Execute(null);
Navigator.NavigationCommand.Execute("/statut"); Navigator.NavigationCommand.Execute("/statut");
} }
[RelayCommand]
private void AllToReadBooksNavigate() private void AllToReadBooksNavigate()
{ {
Manager.GetToBeReadBooksCommand.Execute(null); Manager.GetToBeReadBooksCommand.Execute(null);
Navigator.NavigationCommand.Execute("/later"); Navigator.NavigationCommand.Execute("/later");
} }
[RelayCommand]
private void AllAuthorsNavigate() private void AllAuthorsNavigate()
{ {
Manager.GetAllAuthorsCommand.Execute(null); Manager.GetAllAuthorsCommand.Execute(null);
Navigator.NavigationCommand.Execute("/auteur"); Navigator.NavigationCommand.Execute("/auteur");
} }
[RelayCommand]
private void AllDatesNavigate() private void AllDatesNavigate()
{ {
Manager.GetAllPublishDatesCommand.Execute(null); Manager.GetAllPublishDatesCommand.Execute(null);
Navigator.NavigationCommand.Execute("/date"); Navigator.NavigationCommand.Execute("/date");
} }
[RelayCommand]
private void AllRatingsNavigate() private void AllRatingsNavigate()
{ {
Manager.GetAllRatingsCommand.Execute(null); Manager.GetAllRatingsCommand.Execute(null);

@ -1,5 +1,6 @@
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Alerts;
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,37 +11,24 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class ContactsVM : BaseViewModel [ObservableObject]
public partial class ContactsVM
{ {
#region Fields #region Fields
[ObservableProperty]
private NavigatorVM navigator;
[ObservableProperty]
private ManagerVM manager;
[ObservableProperty]
private bool dataFormIsVisible = false; private bool dataFormIsVisible = false;
#endregion #endregion
#region Properties #region Properties
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
public bool DataFormIsVisible
{
get { return dataFormIsVisible; }
set
{
if (dataFormIsVisible != value)
{
dataFormIsVisible = value;
OnPropertyChanged(nameof(DataFormIsVisible));
}
}
}
public ICommand AddContactDataFormCommand { get; private set; }
public ICommand BookLendedCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -49,19 +37,19 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
AddContactDataFormCommand = new RelayCommand(() => AddContactDataForm());
BookLendedCommand = new RelayCommand<ContactVM>((contactVM) => BookLended(contactVM));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void AddContactDataForm() private void AddContactDataForm()
{ {
DataFormIsVisible = true; DataFormIsVisible = true;
} }
[RelayCommand]
private async Task BookLended(ContactVM contactVM) private async Task BookLended(ContactVM contactVM)
{ {
Manager.LendBookCommand.Execute(contactVM); Manager.LendBookCommand.Execute(contactVM);

@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model; using Model;
using PersonalMVVMToolkit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,71 +12,29 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class DetailsLivreVM : BaseViewModel [ObservableObject]
public partial class DetailsLivreVM
{ {
#region Fields #region Fields
private bool isPickerVisible = false; [ObservableProperty]
private string addFavorisButtonText; private NavigatorVM navigator;
#endregion
#region Properties
public ManagerVM Manager { get; private set; }
public NavigatorVM Navigator { get; private set; }
public BookVM Book { get; private set; }
public bool IsPickerVisible
{
get => isPickerVisible;
set
{
if (isPickerVisible != value)
{
isPickerVisible = value;
OnPropertyChanged(nameof(IsPickerVisible));
}
}
}
public string AddFavorisButtonText [ObservableProperty]
{ private ManagerVM manager;
get
{
Manager.GetFavoriteBooksCommand.Execute(null);
if (Manager.AllFavoriteBooks.Any(favoriteBook => favoriteBook.Id == Book.Id))
{
return addFavorisButtonText = "Supprimer des favoris";
}
else
{
return addFavorisButtonText = "Ajouter aux favoris";
}
}
set
{
if (addFavorisButtonText != value)
{
addFavorisButtonText = value;
OnPropertyChanged(nameof(AddFavorisButtonText));
}
}
}
public ICommand BackButtonCommand { get; private set; }
public ICommand ShowPickerCommand { get; private set; } [ObservableProperty]
private BookVM book;
public ICommand AddRemoveBookToFavoritesCommand { get; private set; } [ObservableProperty]
private bool isPickerVisible = false;
public ICommand AddBookToReadListCommand { get; private set; } [ObservableProperty]
private string addFavorisButtonText;
public ICommand LoanBookCommand { get; private set; } #endregion
public ICommand RemoveBookCommand { get; private set; } #region Properties
#endregion #endregion
@ -86,30 +45,27 @@ namespace LivreLand.ViewModel
Manager = managerVM; Manager = managerVM;
Navigator = navigatorVM; Navigator = navigatorVM;
Book = bookVM; Book = bookVM;
BackButtonCommand = new RelayCommand(() => BackButton());
ShowPickerCommand = new RelayCommand(() => ShowPicker());
AddRemoveBookToFavoritesCommand = new RelayCommand<BookVM>((bookVM) => AddRemoveBookToFavorites(bookVM));
AddBookToReadListCommand = new RelayCommand<BookVM>((bookVM) => AddBookToReadList(bookVM));
LoanBookCommand = new RelayCommand<BookVM>((bookVM) => LoanBook(bookVM));
RemoveBookCommand = new RelayCommand<BookVM>((bookVM) => RemoveBook(bookVM));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void BackButton() private void BackButton()
{ {
Navigator.PopupBackButtonNavigationCommand.Execute(null); Navigator.PopupBackButtonNavigationCommand.Execute(null);
} }
[RelayCommand]
private void ShowPicker() private void ShowPicker()
{ {
Manager.GetAllStatusCommand.Execute(null); Manager.GetAllStatusCommand.Execute(null);
Manager.SelectedStatus = this.Book.Status; Manager.SelectedStatus = Book.Status;
IsPickerVisible = true; IsPickerVisible = true;
} }
[RelayCommand]
private async Task AddRemoveBookToFavorites(BookVM bookVM) private async Task AddRemoveBookToFavorites(BookVM bookVM)
{ {
Manager.CheckBookIsFavoriteCommand.Execute(bookVM); Manager.CheckBookIsFavoriteCommand.Execute(bookVM);
@ -139,6 +95,7 @@ namespace LivreLand.ViewModel
} }
} }
[RelayCommand]
private async Task AddBookToReadList(BookVM bookVM) private async Task AddBookToReadList(BookVM bookVM)
{ {
Manager.UpdateToBeReadBookCommand.Execute(bookVM); Manager.UpdateToBeReadBookCommand.Execute(bookVM);
@ -150,6 +107,7 @@ namespace LivreLand.ViewModel
Navigator.NavigationCommand.Execute("/later"); Navigator.NavigationCommand.Execute("/later");
} }
[RelayCommand]
private void LoanBook(BookVM bookVM) private void LoanBook(BookVM bookVM)
{ {
Manager.SelectedBook = bookVM; Manager.SelectedBook = bookVM;
@ -157,6 +115,7 @@ namespace LivreLand.ViewModel
Navigator.NavigationCommand.Execute("contacts"); Navigator.NavigationCommand.Execute("contacts");
} }
[RelayCommand]
private async Task RemoveBook(BookVM bookVM) private async Task RemoveBook(BookVM bookVM)
{ {
Manager.RemoveBookCommand.Execute(bookVM); Manager.RemoveBookCommand.Execute(bookVM);

@ -1,6 +1,7 @@
using LivreLand.View; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using Model; using Model;
using PersonalMVVMToolkit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,111 +12,39 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class EmpruntsPretsVM : BaseViewModel [ObservableObject]
public partial class EmpruntsPretsVM
{ {
#region Fields #region Fields
[ObservableProperty]
private NavigatorVM navigator;
[ObservableProperty]
private ManagerVM manager;
[ObservableProperty]
private Color pretButtonBackgroundColor = Colors.White; private Color pretButtonBackgroundColor = Colors.White;
[ObservableProperty]
private bool pretButtonIsEnabled = true; private bool pretButtonIsEnabled = true;
[ObservableProperty]
private Color empruntButtonBackgroundColor = Colors.Transparent; private Color empruntButtonBackgroundColor = Colors.Transparent;
[ObservableProperty]
private bool empruntButtonIsEnabled = false; private bool empruntButtonIsEnabled = false;
[ObservableProperty]
private bool pretCollectionIsVisible = true; private bool pretCollectionIsVisible = true;
[ObservableProperty]
private bool empruntCollectionIsVisible = false; private bool empruntCollectionIsVisible = false;
#endregion #endregion
#region Properties #region Properties
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
public Color PretButtonBackgroundColor
{
get { return pretButtonBackgroundColor; }
set
{
if (pretButtonBackgroundColor != value)
{
pretButtonBackgroundColor = value;
OnPropertyChanged(nameof(PretButtonBackgroundColor));
}
}
}
public bool PretButtonIsEnabled
{
get { return pretButtonIsEnabled; }
set
{
if (pretButtonIsEnabled != value)
{
pretButtonIsEnabled = value;
OnPropertyChanged(nameof(PretButtonIsEnabled));
}
}
}
public Color EmpruntButtonBackgroundColor
{
get { return empruntButtonBackgroundColor; }
set
{
if (empruntButtonBackgroundColor != value)
{
empruntButtonBackgroundColor = value;
OnPropertyChanged(nameof(EmpruntButtonBackgroundColor));
}
}
}
public bool EmpruntButtonIsEnabled
{
get { return empruntButtonIsEnabled; }
set
{
if (empruntButtonIsEnabled != value)
{
empruntButtonIsEnabled = value;
OnPropertyChanged(nameof(EmpruntButtonIsEnabled));
}
}
}
public bool EmpruntCollectionIsVisible
{
get { return empruntCollectionIsVisible; }
set
{
if (empruntCollectionIsVisible != value)
{
empruntCollectionIsVisible = value;
OnPropertyChanged(nameof(EmpruntCollectionIsVisible));
}
}
}
public bool PretCollectionIsVisible
{
get { return pretCollectionIsVisible; }
set
{
if (pretCollectionIsVisible != value)
{
pretCollectionIsVisible = value;
OnPropertyChanged(nameof(PretCollectionIsVisible));
}
}
}
public ICommand OnSelectionLoanChangedCommand { get; private set; }
public ICommand OnSelectionBorrowingChangedCommand { get; private set; }
public ICommand PretsButtonCommand { get; private set; }
public ICommand EmpruntsButtonCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -124,21 +53,18 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionLoanChangedCommand = new RelayCommand<LoanVM>((loanVM) => OnSelectionLoanChanged(loanVM));
OnSelectionBorrowingChangedCommand = new RelayCommand<BorrowingVM>((borrowingVM) => OnSelectionBorrowingChanged(borrowingVM));
PretsButtonCommand = new RelayCommand(() => PretsButtonClicked());
EmpruntsButtonCommand = new RelayCommand(() => EmpruntsButtonClicked());
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void OnSelectionLoanChanged(LoanVM loanVM) private void OnSelectionLoanChanged(LoanVM loanVM)
{ {
if (loanVM != null) if (loanVM != null)
{ {
foreach (var b in Manager.AllCurrentLoans) foreach (var b in Manager.CurrentLoans)
{ {
if (b.Book.Id == loanVM.Book.Id) if (b.Book.Id == loanVM.Book.Id)
{ {
@ -150,11 +76,12 @@ namespace LivreLand.ViewModel
} }
} }
[RelayCommand]
private void OnSelectionBorrowingChanged(BorrowingVM borrowingVM) private void OnSelectionBorrowingChanged(BorrowingVM borrowingVM)
{ {
if (borrowingVM != null) if (borrowingVM != null)
{ {
foreach (var b in Manager.AllCurrentBorrowings) foreach (var b in Manager.CurrentBorrowings)
{ {
if (b.Book.Id == borrowingVM.Book.Id) if (b.Book.Id == borrowingVM.Book.Id)
{ {
@ -166,6 +93,7 @@ namespace LivreLand.ViewModel
} }
} }
[RelayCommand]
public void PretsButtonClicked() public void PretsButtonClicked()
{ {
if (App.Current.PlatformAppTheme == AppTheme.Light) if (App.Current.PlatformAppTheme == AppTheme.Light)
@ -186,6 +114,7 @@ namespace LivreLand.ViewModel
EmpruntCollectionIsVisible = true; EmpruntCollectionIsVisible = true;
} }
[RelayCommand]
public void EmpruntsButtonClicked() public void EmpruntsButtonClicked()
{ {
if (App.Current.PlatformAppTheme == AppTheme.Light) if (App.Current.PlatformAppTheme == AppTheme.Light)

@ -1,4 +1,4 @@
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,13 +8,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class FavorisVM : BaseViewModel [ObservableObject]
public partial class FavorisVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
#region Properties
#endregion #endregion

@ -1,4 +1,5 @@
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,15 +10,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class FiltrageAuteurVM : BaseViewModel [ObservableObject]
public partial class FiltrageAuteurVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand NavigateAuthorPageCommand { get; private set; } #region Properties
#endregion #endregion
@ -27,13 +33,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
NavigateAuthorPageCommand = new RelayCommand(() => NavigateAuthorPage());
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void NavigateAuthorPage() private void NavigateAuthorPage()
{ {
Manager.GetBooksByAuthorCommand.Execute(null); Manager.GetBooksByAuthorCommand.Execute(null);

@ -1,4 +1,5 @@
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,15 +10,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class FiltrageDateVM : BaseViewModel [ObservableObject]
public partial class FiltrageDateVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand NavigateDatePageCommand { get; private set; } #region Properties
#endregion #endregion
@ -27,13 +33,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
NavigateDatePageCommand = new RelayCommand(() => NavigateDatePage());
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void NavigateDatePage() private void NavigateDatePage()
{ {
Manager.GetBooksByDateCommand.Execute(null); Manager.GetBooksByDateCommand.Execute(null);

@ -1,4 +1,5 @@
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,15 +10,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class FiltrageNoteVM : BaseViewModel [ObservableObject]
public partial class FiltrageNoteVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand NavigateRatingPageCommand { get; private set; } #region Properties
#endregion #endregion
@ -27,13 +33,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
NavigateRatingPageCommand = new RelayCommand(() => NavigateRatingPage());
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void NavigateRatingPage() private void NavigateRatingPage()
{ {
Manager.GetBooksByRatingCommand.Execute(null); Manager.GetBooksByRatingCommand.Execute(null);

@ -1,4 +1,6 @@
using CommunityToolkit.Maui.Views; using CommunityToolkit.Maui.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LivreLand.View; using LivreLand.View;
using LivreLand.View.ContentViews; using LivreLand.View.ContentViews;
using System; using System;
@ -10,14 +12,14 @@ using System.Windows.Input;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class NavigatorVM [ObservableObject]
public partial class NavigatorVM
{ {
#region Properties #region Fields
#endregion
public ICommand NavigationCommand { get; } #region Properties
public ICommand PopupHomePlusNavigationCommand { get; }
public ICommand PopupISBNNavigationCommand { get; }
public ICommand PopupBackButtonNavigationCommand { get; }
#endregion #endregion
@ -25,17 +27,37 @@ namespace LivreLand.ViewModel
public NavigatorVM() public NavigatorVM()
{ {
NavigationCommand = new Command(async (target) => await Shell.Current.GoToAsync($"//library/{target}"));
PopupHomePlusNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupHomePlusButtonView(this)));
PopupISBNNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupISBNView(Application.Current.Handler.MauiContext.Services.GetService<PopupISBNVM>())));
PopupBackButtonNavigationCommand = new Command(() => App.Current.MainPage.Navigation.PopAsync());
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private async Task Navigation(string target)
{
await Shell.Current.GoToAsync($"//library/{target}");
}
[RelayCommand]
private async Task PopupHomePlusNavigation()
{
await App.Current.MainPage.ShowPopupAsync(new PopupHomePlusButtonView(this));
}
[RelayCommand]
private async Task PopupISBNNavigation()
{
await App.Current.MainPage.ShowPopupAsync(new PopupISBNView(Application.Current.Handler.MauiContext.Services.GetService<PopupISBNVM>()));
}
[RelayCommand]
private async Task PopupBackButtonNavigation()
{
await App.Current.MainPage.Navigation.PopAsync();
}
#endregion #endregion
} }
} }

@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model; using Model;
using PersonalMVVMToolkit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,15 +12,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class PopupISBNVM : BaseViewModel [ObservableObject]
public partial class PopupISBNVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand AddBookCommand { get; private set; } #region Properties
#endregion #endregion
@ -29,13 +35,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
AddBookCommand = new RelayCommand<string>((text) => AddBook(text));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private async Task AddBook(string entryText) private async Task AddBook(string entryText)
{ {
Manager.AddBookCommand.Execute(entryText); Manager.AddBookCommand.Execute(entryText);

@ -1,6 +1,7 @@
using Camera.MAUI; using Camera.MAUI;
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Alerts;
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -13,60 +14,39 @@ using ZXing;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class ScanVM : BaseViewModel [ObservableObject]
public partial class ScanVM
{ {
#region Fields #region Fields
[ObservableProperty]
private NavigatorVM navigator;
[ObservableProperty]
private ManagerVM manager;
[ObservableProperty]
private CameraView cameraView; private CameraView cameraView;
[ObservableProperty]
private CameraInfo camera = null; private CameraInfo camera = null;
[ObservableProperty]
private ObservableCollection<CameraInfo> cameras = new(); private ObservableCollection<CameraInfo> cameras = new();
[ObservableProperty]
private Result[] result; private Result[] result;
[ObservableProperty]
private string barcodeText = "ISBN"; private string barcodeText = "ISBN";
[ObservableProperty]
private bool addIsVisible = false; private bool addIsVisible = false;
#endregion #endregion
#region Properties #region Properties
public CameraView CameraView
{
get => cameraView;
set
{
if (cameraView != value)
{
cameraView = value;
OnPropertyChanged(nameof(CameraView));
}
}
}
public CameraInfo Camera
{
get => camera;
set
{
if (camera != value)
{
camera = value;
OnPropertyChanged(nameof(Camera));
}
}
}
public ObservableCollection<CameraInfo> Cameras
{
get => cameras;
set
{
if (cameras != value)
{
cameras = value;
OnPropertyChanged(nameof(Cameras));
}
}
}
public int CamerasCount public int CamerasCount
{ {
get => Cameras.Count(); get => Cameras.Count();
@ -92,42 +72,6 @@ namespace LivreLand.ViewModel
} }
} }
public string BarcodeText
{
get => barcodeText;
set
{
if (barcodeText != value)
{
barcodeText = value;
OnPropertyChanged(nameof(BarcodeText));
}
}
}
public bool AddIsVisible
{
get => addIsVisible;
set
{
if (addIsVisible != value)
{
addIsVisible = value;
OnPropertyChanged(nameof(AddIsVisible));
}
}
}
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
public ICommand CamerasLoadCommand { get; private set; }
public ICommand BarcodeDetectCommand { get; private set; }
public ICommand AddBookISBNDetectedCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -136,15 +80,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
CamerasLoadCommand = new RelayCommand(() => CamerasLoad());
BarcodeDetectCommand = new RelayCommand(() => BarcodeDetect());
AddBookISBNDetectedCommand = new RelayCommand<string>((isbn) => AddBookISBNDetected(isbn));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private async Task CamerasLoad() private async Task CamerasLoad()
{ {
if (Cameras.Count > 0) if (Cameras.Count > 0)
@ -158,6 +100,7 @@ namespace LivreLand.ViewModel
} }
} }
[RelayCommand]
private async Task BarcodeDetect() private async Task BarcodeDetect()
{ {
MainThread.BeginInvokeOnMainThread(() => MainThread.BeginInvokeOnMainThread(() =>
@ -167,6 +110,7 @@ namespace LivreLand.ViewModel
}); });
} }
[RelayCommand]
private async Task AddBookISBNDetected(string isbn) private async Task AddBookISBNDetected(string isbn)
{ {
Manager.AddBookCommand.Execute(isbn); Manager.AddBookCommand.Execute(isbn);

@ -1,5 +1,6 @@
using LivreLand.View; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,15 +11,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class StatutLectureVM : BaseViewModel [ObservableObject]
public partial class StatutLectureVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand OnSelectionChangedCommand { get; private set; } #region Properties
#endregion #endregion
@ -28,13 +34,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void OnSelectionChanged(BookVM bookVM) private void OnSelectionChanged(BookVM bookVM)
{ {
if (bookVM != null) if (bookVM != null)

@ -1,5 +1,6 @@
using LivreLand.View; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,15 +11,20 @@ using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
{ {
public class TousVM : BaseViewModel [ObservableObject]
public partial class TousVM
{ {
#region Properties #region Fields
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; } [ObservableProperty]
private ManagerVM manager;
public ManagerVM Manager { get; private set; } #endregion
public ICommand OnSelectionChangedCommand { get; private set; } #region Properties
#endregion #endregion
@ -28,13 +34,13 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
} }
#endregion #endregion
#region Methods #region Methods
[RelayCommand]
private void OnSelectionChanged(BookVM bookVM) private void OnSelectionChanged(BookVM bookVM)
{ {
if (bookVM != null) if (bookVM != null)

@ -6,4 +6,9 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
</Project> </Project>

@ -6,4 +6,9 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
</Project> </Project>

@ -6,6 +6,11 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubbedDTO\StubbedDTO.csproj" /> <ProjectReference Include="..\StubbedDTO\StubbedDTO.csproj" />

@ -33,4 +33,8 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="*\*.json" /> <EmbeddedResource Include="*\*.json" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
</Project> </Project>

@ -7,6 +7,11 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Stub\Stub.csproj" /> <ProjectReference Include="..\Stub\Stub.csproj" />

@ -6,4 +6,9 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
</Project> </Project>

@ -1,5 +1,5 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,40 +8,27 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class AuthorVM : BaseViewModel<Author> [ObservableObject]
public partial class AuthorVM
{ {
#region Fields #region Fields
private int nbBooksWritten { get; set; } [ObservableProperty]
private int nbBooksWritten;
[ObservableProperty]
private string name;
#endregion #endregion
#region Properties #region Properties
public string Name
{
get => Model.Name;
set
{
Model.Name = value;
}
}
public int NbBooksWritten
{
get => nbBooksWritten;
set
{
nbBooksWritten = value;
}
}
#endregion #endregion
#region Constructor #region Constructor
public AuthorVM(Author model) : base(model) public AuthorVM(Author model)
{ {
} }

@ -1,5 +1,5 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,82 +8,57 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class BookVM : BaseViewModel<Book> [ObservableObject]
public partial class BookVM
{ {
#region Fields #region Fields
#endregion [ObservableProperty]
private string id;
#region Properties [ObservableProperty]
private string isbn13;
public string Id [ObservableProperty]
{ private string title;
get => Model.Id;
}
public string ISBN13 [ObservableProperty]
{ private List<string> publishers;
get => Model.ISBN13;
}
public string Title [ObservableProperty]
{ private DateTime publishDate;
get => Model.Title;
}
public List<string> Publishers [ObservableProperty]
{ private List<AuthorVM> authors;
get => Model.Publishers;
}
public DateTime PublishDate [ObservableProperty]
{ private string author;
get => Model.PublishDate;
}
public List<AuthorVM> Authors [ObservableProperty]
{ private Status status;
get => Model.Authors.Select(a => new AuthorVM(a)).ToList();
}
public string Author => Model.Authors.Count > 0 ? Model.Authors.First().Name : "Auteur inconnu"; [ObservableProperty]
private int nbPages;
public Status Status [ObservableProperty]
{ private Languages language;
get => Model.Status;
}
public int NbPages [ObservableProperty]
{ private string imageSmall;
get => Model.NbPages;
}
public Languages Language [ObservableProperty]
{ private float? userRating;
get => Model.Language;
}
public string ImageSmall #endregion
{
get => Model.ImageSmall;
}
public float? UserRating #region Properties
{
get => Model?.UserRating;
set
{
if (Model == null) return;
SetProperty(Model.UserRating, value, rating => Model.UserRating = rating);
}
}
#endregion #endregion
#region Constructor #region Constructor
public BookVM(Book b) : base(b) public BookVM(Book b)
{ {
} }

@ -1,5 +1,5 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,47 +8,35 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class BorrowingVM : BaseViewModel<Borrowing> [ObservableObject]
public partial class BorrowingVM
{ {
#region Fields #region Fields
#endregion [ObservableProperty]
private string id;
#region Properties [ObservableProperty]
private BookVM book;
public string Id [ObservableProperty]
{ private ContactVM owner;
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
}
public BookVM Book [ObservableProperty]
{ private DateTime borrowedAt;
get => new BookVM(Model.Book);
}
public ContactVM Owner [ObservableProperty]
{ private DateTime returnedAt;
get => new ContactVM(Model.Owner);
}
public DateTime BorrowedAt #endregion
{
get => Model.BorrowedAt;
set => SetProperty(Model.BorrowedAt, value, v => Model.BorrowedAt = value);
}
public DateTime? ReturnedAt #region Properties
{
get => Model.ReturnedAt;
set => SetProperty(Model.ReturnedAt, value, v => Model.ReturnedAt = value);
}
#endregion #endregion
#region Constructor #region Constructor
public BorrowingVM(Borrowing b) : base(b) public BorrowingVM(Borrowing b)
{ {
} }

@ -1,5 +1,5 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,37 +8,29 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class ContactVM : BaseViewModel<Model.Contact> [ObservableObject]
public partial class ContactVM
{ {
#region Fields #region Fields
#endregion [ObservableProperty]
private string id;
#region Properties [ObservableProperty]
private string firstName;
public string Id [ObservableProperty]
{ private string lastName;
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
}
public string FirstName #endregion
{
get => Model.FirstName;
set => SetProperty(Model.FirstName, value, v => Model.FirstName = value);
}
public string LastName #region Properties
{
get => Model.LastName;
set => SetProperty(Model.LastName, value, v => Model.LastName = value);
}
#endregion #endregion
#region Constructor #region Constructor
public ContactVM(Model.Contact c) : base(c) public ContactVM(Model.Contact c)
{ {
} }

@ -1,5 +1,5 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,47 +8,35 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class LoanVM : BaseViewModel<Loan> [ObservableObject]
public partial class LoanVM
{ {
#region Fields #region Fields
#endregion [ObservableProperty]
private string id;
#region Properties [ObservableProperty]
private BookVM book;
public string Id [ObservableProperty]
{ private ContactVM loaner;
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
}
public BookVM Book [ObservableProperty]
{ private DateTime loanedAt;
get => new BookVM(Model.Book);
}
public ContactVM Loaner [ObservableProperty]
{ private DateTime? returnedAt;
get => new ContactVM(Model.Loaner);
}
public DateTime LoanedAt #endregion
{
get => Model.LoanedAt;
set => SetProperty(Model.LoanedAt, value, v => Model.LoanedAt = value);
}
public DateTime? ReturnedAt #region Properties
{
get => Model.ReturnedAt;
set => SetProperty(Model.ReturnedAt, value, v => Model.ReturnedAt = value);
}
#endregion #endregion
#region Constructor #region Constructor
public LoanVM(Loan l) : base(l) public LoanVM(Loan l)
{ {
} }

@ -1,5 +1,6 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.Input;
using Model;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -8,419 +9,128 @@ using static System.Reflection.Metadata.BlobBuilder;
namespace ViewModels namespace ViewModels
{ {
public class ManagerVM : BaseViewModel<Manager> [ObservableObject]
public partial class ManagerVM
{ {
#region Fields #region Fields
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>(); [ObservableProperty]
private IEnumerable<IGrouping<string, BookVM>> groupedBooks; private Manager model;
private IEnumerable<IGrouping<Status, BookVM>> groupedStatusBooks;
private readonly ObservableCollection<AuthorVM> authors = new ObservableCollection<AuthorVM>(); [ObservableProperty]
private readonly ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>(); private ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
private readonly ObservableCollection<RatingsVM> ratings = new ObservableCollection<RatingsVM>();
private readonly ObservableCollection<BookVM> toBeReadBooks = new ObservableCollection<BookVM>(); [ObservableProperty]
private readonly ObservableCollection<BookVM> favoriteBooks = new ObservableCollection<BookVM>(); private IEnumerable<IGrouping<string, BookVM>> groupedBooks;
private readonly ObservableCollection<LoanVM> currentLoans = new ObservableCollection<LoanVM>();
private IEnumerable<IGrouping<ContactVM, LoanVM>> currentGroupedLoans;
private readonly ObservableCollection<LoanVM> pastLoans = new ObservableCollection<LoanVM>();
private IEnumerable<IGrouping<ContactVM, LoanVM>> pastGroupedLoans;
private readonly ObservableCollection<BorrowingVM> currentBorrowings = new ObservableCollection<BorrowingVM>();
private IEnumerable<IGrouping<ContactVM, BorrowingVM>> currentGroupedBorrowings;
private readonly ObservableCollection<BorrowingVM> pastBorrowings = new ObservableCollection<BorrowingVM>();
private IEnumerable<IGrouping<ContactVM, BorrowingVM>> pastGroupedBorrowings;
private readonly ObservableCollection<ContactVM> contacts = new ObservableCollection<ContactVM>();
private readonly ObservableCollection<Status> status = new ObservableCollection<Status>();
private int index;
private long nbBooks;
private BookVM selectedBook;
private AuthorVM selectedAuthor;
private PublishDateVM selectedDate;
private RatingsVM selectedRating;
private Status selectedStatus;
private ContactVM selectedContact;
private LoanVM selectedLoan;
private BorrowingVM selectedBorrowing;
private string entryText;
private string givenFirstName;
private string givenLastName;
private bool isFavorite;
#endregion [ObservableProperty]
private IEnumerable<IGrouping<Status, BookVM>> groupedStatusBooks;
#region Properties [ObservableProperty]
private ObservableCollection<AuthorVM> authors = new ObservableCollection<AuthorVM>();
public ObservableCollection<BookVM> AllBooks [ObservableProperty]
{ private ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>();
get => books;
}
public IEnumerable<IGrouping<string, BookVM>> GroupedBooks [ObservableProperty]
{ private ObservableCollection<RatingsVM> ratings = new ObservableCollection<RatingsVM>();
get => groupedBooks;
set => SetProperty(ref groupedBooks, value);
}
public IEnumerable<IGrouping<Status, BookVM>> GroupedStatusBooks [ObservableProperty]
{ private ObservableCollection<BookVM> toBeReadBooks = new ObservableCollection<BookVM>();
get => groupedStatusBooks;
set => SetProperty(ref groupedStatusBooks, value);
}
public ObservableCollection<AuthorVM> AllAuthors [ObservableProperty]
{ private ObservableCollection<BookVM> favoriteBooks = new ObservableCollection<BookVM>();
get => authors;
}
public ObservableCollection<PublishDateVM> AllPublishDates [ObservableProperty]
{ private ObservableCollection<LoanVM> currentLoans = new ObservableCollection<LoanVM>();
get => publishDates;
}
public ObservableCollection<RatingsVM> AllRatings [ObservableProperty]
{ private IEnumerable<IGrouping<ContactVM, LoanVM>> currentGroupedLoans;
get => ratings;
}
public ObservableCollection<BookVM> ToBeReadBooks [ObservableProperty]
{ private ObservableCollection<LoanVM> pastLoans = new ObservableCollection<LoanVM>();
get => toBeReadBooks;
}
public ObservableCollection<BookVM> AllFavoriteBooks [ObservableProperty]
{ private IEnumerable<IGrouping<ContactVM, LoanVM>> pastGroupedLoans;
get => favoriteBooks;
}
public ObservableCollection<LoanVM> AllCurrentLoans [ObservableProperty]
{ private ObservableCollection<BorrowingVM> currentBorrowings = new ObservableCollection<BorrowingVM>();
get => currentLoans;
}
public IEnumerable<IGrouping<ContactVM, LoanVM>> AllCurrentGroupedLoans [ObservableProperty]
{ private IEnumerable<IGrouping<ContactVM, BorrowingVM>> currentGroupedBorrowings;
get => currentGroupedLoans;
set => SetProperty(ref currentGroupedLoans, value);
}
public ObservableCollection<LoanVM> AllPastLoans [ObservableProperty]
{ private ObservableCollection<BorrowingVM> pastBorrowings = new ObservableCollection<BorrowingVM>();
get => pastLoans;
}
public IEnumerable<IGrouping<ContactVM, LoanVM>> AllPastGroupedLoans [ObservableProperty]
{ private IEnumerable<IGrouping<ContactVM, BorrowingVM>> pastGroupedBorrowings;
get => pastGroupedLoans;
set => SetProperty(ref pastGroupedLoans, value);
}
public ObservableCollection<BorrowingVM> AllCurrentBorrowings [ObservableProperty]
{ private ObservableCollection<ContactVM> contacts = new ObservableCollection<ContactVM>();
get => currentBorrowings;
}
public IEnumerable<IGrouping<ContactVM, BorrowingVM>> AllCurrentGroupedBorrowings [ObservableProperty]
{ private ObservableCollection<Status> allStatus = new ObservableCollection<Status>();
get => currentGroupedBorrowings;
set => SetProperty(ref currentGroupedBorrowings, value);
}
public ObservableCollection<BorrowingVM> AllPastBorrowings [ObservableProperty]
{ private int indexPage;
get => pastBorrowings;
}
public IEnumerable<IGrouping<ContactVM, BorrowingVM>> AllPastGroupedBorrowings [ObservableProperty]
{ private long nbBooks;
get => pastGroupedBorrowings;
set => SetProperty(ref pastGroupedBorrowings, value);
}
public ObservableCollection<ContactVM> AllContacts [ObservableProperty]
{ private BookVM selectedBook;
get => contacts;
}
public ObservableCollection<Status> AllStatus [ObservableProperty]
{ private AuthorVM selectedAuthor;
get => status;
}
public BookVM SelectedBook [ObservableProperty]
{ private PublishDateVM selectedDate;
get { return selectedBook; }
set
{
if (selectedBook != value)
{
selectedBook = value;
OnPropertyChanged(nameof(SelectedBook));
}
}
}
public AuthorVM SelectedAuthor [ObservableProperty]
{ private RatingsVM selectedRating;
get { return selectedAuthor; }
set
{
if (selectedAuthor != value)
{
selectedAuthor = value;
OnPropertyChanged(nameof(SelectedAuthor));
}
}
}
public PublishDateVM SelectedDate [ObservableProperty]
{ private Status selectedStatus;
get { return selectedDate; }
set
{
if (selectedDate != value)
{
selectedDate = value;
OnPropertyChanged(nameof(SelectedDate));
}
}
}
public RatingsVM SelectedRating [ObservableProperty]
{ private ContactVM selectedContact;
get { return selectedRating; }
set
{
if (selectedRating != value)
{
selectedRating = value;
OnPropertyChanged(nameof(SelectedRating));
}
}
}
public Status SelectedStatus [ObservableProperty]
{ private LoanVM selectedLoan;
get { return selectedStatus; }
set
{
if (selectedStatus != value)
{
selectedStatus = value;
OnPropertyChanged(nameof(SelectedStatus));
}
}
}
public ContactVM SelectedContact [ObservableProperty]
{ private BorrowingVM selectedBorrowing;
get { return selectedContact; }
set
{
if (selectedContact != value)
{
selectedContact = value;
OnPropertyChanged(nameof(SelectedContact));
}
}
}
public LoanVM SelectedLoan [ObservableProperty]
{ private string entryText;
get { return selectedLoan; }
set
{
if (selectedLoan != value)
{
selectedLoan = value;
OnPropertyChanged(nameof(SelectedLoan));
}
}
}
public BorrowingVM SelectedBorrowing [ObservableProperty]
{ private string givenFirstName;
get { return selectedBorrowing; }
set
{
if (selectedBorrowing != value)
{
selectedBorrowing = value;
OnPropertyChanged(nameof(SelectedBorrowing));
}
}
}
public string EntryText [ObservableProperty]
{ private string givenLastName;
get { return entryText; }
set
{
if (entryText != value)
{
entryText = value;
OnPropertyChanged(nameof(EntryText));
}
}
}
public string GivenFirstName [ObservableProperty]
{ private bool isFavorite;
get { return givenFirstName; }
set
{
if (givenFirstName != value)
{
givenFirstName = value;
OnPropertyChanged(nameof(GivenFirstName));
}
}
}
public string GivenLastName #endregion
{
get { return givenLastName; }
set
{
if (givenLastName != value)
{
givenLastName = value;
OnPropertyChanged(nameof(GivenLastName));
}
}
}
public bool IsFavorite #region Properties
{
get { return isFavorite; }
set
{
if (isFavorite != value)
{
isFavorite = value;
OnPropertyChanged(nameof(IsFavorite));
}
}
}
public string SearchTitle { get; private set; } public string SearchTitle { get; private set; }
public int Index
{
get => index;
set => SetProperty(ref index, value);
}
public int Count { get; set; } = 5; public int Count { get; set; } = 5;
public long NbBooks
{
get => nbBooks;
set
{
SetProperty(ref nbBooks, value);
OnPropertyChanged(nameof(NbPages));
}
}
public int NbPages => (int)((NbBooks - 1) / Count); public int NbPages => (int)((NbBooks - 1) / Count);
public ICommand PreviousCommand { get; private set; }
public ICommand NextCommand { get; private set; }
public ICommand GetBooksByTitleCommand { get; private set; }
public ICommand GetBooksFromCollectionCommand { get; private set; }
public ICommand AddBookCommand { 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 GetAllAuthorsCommand { get; private set; }
public ICommand GetBooksByDateCommand { get; private set; }
public ICommand GetAllPublishDatesCommand { get; private set; }
public ICommand GetBooksByRatingCommand { get; private set; }
public ICommand GetAllRatingsCommand { get; private set; }
public ICommand GetAllStatusCommand { get; private set; }
public ICommand GetToBeReadBooksCommand { get; private set; }
public ICommand GetFavoriteBooksCommand { get; private set; }
public ICommand AddToFavoritesCommand { get; private set; }
public ICommand RemoveFromFavoritesCommand { get; private set; }
public ICommand CheckBookIsFavoriteCommand { get; private set; }
public ICommand GetCurrentLoansCommand { get; private set; }
public ICommand GetPastLoansCommand { get; private set; }
public ICommand GetCurrentBorrowingsCommand { get; private set; }
public ICommand GetPastBorrowingsCommand { get; private set; }
public ICommand LendBookCommand { get; private set; }
public ICommand GetContactsCommand { get; private set; }
public ICommand AddContactCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
public ManagerVM(Manager model) : base(model) public ManagerVM(Manager model)
{ {
PreviousCommand = new RelayCommand(() => Previous()); Model = model;
NextCommand = new RelayCommand(() => Next());
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
AddBookCommand = new RelayCommand<string>((isbn) => AddBook(isbn));
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());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate());
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
GetBooksByRatingCommand = new RelayCommand(() => GetBooksByRating());
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
GetAllStatusCommand = new RelayCommand(() => GetAllStatus());
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
GetFavoriteBooksCommand = new RelayCommand(() => GetFavoriteBooks());
AddToFavoritesCommand = new RelayCommand<BookVM>(bookVM => AddToFavorites(bookVM));
RemoveFromFavoritesCommand = new RelayCommand<BookVM>(bookVM => RemoveFromFavorites(bookVM));
CheckBookIsFavoriteCommand = new RelayCommand<BookVM>(bookVM => CheckBookIsFavorite(bookVM));
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
GetPastLoansCommand = new RelayCommand(() => GetPastLoans());
GetCurrentBorrowingsCommand = new RelayCommand(() => GetCurrentBorrowings());
GetPastBorrowingsCommand = new RelayCommand(() => GetPastBorrowings());
LendBookCommand = new RelayCommand<ContactVM>((contactVM) => LendBook(contactVM));
GetContactsCommand = new RelayCommand(() => GetContacts());
AddContactCommand = new RelayCommand(() => AddContact());
//GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book))); //GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book)));
} }
@ -430,41 +140,45 @@ namespace ViewModels
#region Methods #region Methods
[RelayCommand]
private async Task Previous() private async Task Previous()
{ {
if (Index > 0) if (IndexPage > 0)
{ {
Index--; IndexPage--;
await GetBooksFromCollection(); await GetBooksFromCollection();
} }
} }
[RelayCommand]
private async Task Next() private async Task Next()
{ {
if (Index < NbPages) if (IndexPage < NbPages)
{ {
Index++; IndexPage++;
await GetBooksFromCollection(); await GetBooksFromCollection();
} }
} }
[RelayCommand]
private async Task GetBooksFromCollection() private async Task GetBooksFromCollection()
{ {
var result = await Model.GetBooksFromCollection(Index, Count); var result = await Model.GetBooksFromCollection(IndexPage, Count);
NbBooks = result.count; NbBooks = result.count;
IEnumerable<Book> someBooks = result.books; IEnumerable<Book> someBooks = result.books;
someBooks = someBooks.OrderBy(b => b.Status); someBooks = someBooks.OrderBy(b => b.Status);
books.Clear(); Books.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
books.Add(b); Books.Add(b);
GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); GroupedBooks = Books.GroupBy(b => b.Author).OrderBy(group => group.Key);
GroupedStatusBooks = AllBooks.GroupBy(b => b.Status).OrderBy(group => group.Key); GroupedStatusBooks = Books.GroupBy(b => b.Status).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedBooks));
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(Books));
} }
[RelayCommand]
private async Task AddBook(string isbn) private async Task AddBook(string isbn)
{ {
var result = await Model.GetBookByISBN(isbn); var result = await Model.GetBookByISBN(isbn);
@ -475,12 +189,14 @@ namespace ViewModels
GetBooksFromCollectionCommand.Execute(null); GetBooksFromCollectionCommand.Execute(null);
} }
[RelayCommand]
private async Task UpdateBook(BookVM bookVM) private async Task UpdateBook(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);
await Model.UpdateBook(book); await Model.UpdateBook(book);
} }
[RelayCommand]
private async Task UpdateStatusBook(BookVM bookVM) private async Task UpdateStatusBook(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);
@ -491,6 +207,7 @@ namespace ViewModels
OnPropertyChanged(nameof(bookVM)); OnPropertyChanged(nameof(bookVM));
} }
[RelayCommand]
private async Task UpdateToBeReadBook(BookVM bookVM) private async Task UpdateToBeReadBook(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);
@ -498,6 +215,7 @@ namespace ViewModels
await Model.UpdateBook(book); await Model.UpdateBook(book);
} }
[RelayCommand]
private async Task RemoveBook(BookVM bookVM) private async Task RemoveBook(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);
@ -506,6 +224,7 @@ namespace ViewModels
await GetBooksFromCollection(); await GetBooksFromCollection();
} }
[RelayCommand]
private async Task GetBooksByAuthor() private async Task GetBooksByAuthor()
{ {
var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, 0, 1000); var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, 0, 1000);
@ -515,12 +234,13 @@ namespace ViewModels
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
books.Add(b); books.Add(b);
GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); GroupedBooks = Books.GroupBy(b => b.Author).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedBooks));
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(Books));
} }
[RelayCommand]
private async Task GetAllAuthors() private async Task GetAllAuthors()
{ {
var result = await Model.GetBooksFromCollection(0, 1000); var result = await Model.GetBooksFromCollection(0, 1000);
@ -535,9 +255,10 @@ namespace ViewModels
a.NbBooksWritten++; a.NbBooksWritten++;
} }
} }
OnPropertyChanged(nameof(AllAuthors)); OnPropertyChanged(nameof(Authors));
} }
[RelayCommand]
private async Task GetBooksByDate() private async Task GetBooksByDate()
{ {
var result = await Model.GetBooksFromCollection(0, 1000); var result = await Model.GetBooksFromCollection(0, 1000);
@ -549,42 +270,44 @@ namespace ViewModels
if (b.PublishDate.Year == SelectedDate.PublishDate.Year) if (b.PublishDate.Year == SelectedDate.PublishDate.Year)
{ {
books.Add(b); books.Add(b);
GroupedBooks = AllBooks.GroupBy(b => b.PublishDate.Year.ToString()).OrderBy(group => group.Key); GroupedBooks = Books.GroupBy(b => b.PublishDate.Year.ToString()).OrderBy(group => group.Key);
} }
} }
OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedBooks));
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(Books));
} }
[RelayCommand]
private async Task GetAllPublishDates() private async Task GetAllPublishDates()
{ {
var result = await Model.GetBooksFromCollection(0, 1000); var result = await Model.GetBooksFromCollection(0, 1000);
IEnumerable<Book> someBooks = result.books; IEnumerable<Book> someBooks = result.books;
books.Clear(); Books.Clear();
publishDates.Clear(); PublishDates.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
var date = new PublishDateVM { PublishDate = b.PublishDate }; var date = new PublishDateVM { PublishDate = b.PublishDate };
date.NbBooksWritten++; date.NbBooksWritten++;
publishDates.Add(date); PublishDates.Add(date);
foreach (var p in publishDates) foreach (var p in PublishDates)
{ {
if (date.PublishDate.Year == p.PublishDate.Year && !date.Equals(p)) if (date.PublishDate.Year == p.PublishDate.Year && !date.Equals(p))
{ {
p.NbBooksWritten++; p.NbBooksWritten++;
publishDates.Remove(date); PublishDates.Remove(date);
} }
} }
} }
OnPropertyChanged(nameof(AllPublishDates)); OnPropertyChanged(nameof(PublishDates));
} }
[RelayCommand]
private async Task GetBooksByRating() private async Task GetBooksByRating()
{ {
var result = await Model.GetBooksFromCollection(0, 1000); var result = await Model.GetBooksFromCollection(0, 1000);
NbBooks = result.count; NbBooks = result.count;
IEnumerable<Book> someBooks = result.books; IEnumerable<Book> someBooks = result.books;
books.Clear(); Books.Clear();
var groupedBooks = someBooks var groupedBooks = someBooks
.Where(book => book.UserRating.HasValue) .Where(book => book.UserRating.HasValue)
@ -595,17 +318,16 @@ namespace ViewModels
GroupedBooks = groupedBooks; GroupedBooks = groupedBooks;
OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedBooks));
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(Books));
} }
[RelayCommand]
private async Task GetAllRatings() private async Task GetAllRatings()
{ {
var result = await Model.GetBooksFromCollection(0, 1000); var result = await Model.GetBooksFromCollection(0, 1000);
IEnumerable<Book> someBooks = result.books; IEnumerable<Book> someBooks = result.books;
books.Clear(); Books.Clear();
ratings.Clear(); Ratings.Clear();
Dictionary<string, List<BookVM>> groupedBooks = new Dictionary<string, List<BookVM>>(); Dictionary<string, List<BookVM>> groupedBooks = new Dictionary<string, List<BookVM>>();
@ -639,19 +361,21 @@ namespace ViewModels
ratings.Add(rating); ratings.Add(rating);
} }
OnPropertyChanged(nameof(AllRatings)); OnPropertyChanged(nameof(Ratings));
} }
[RelayCommand]
private async Task GetAllStatus() private async Task GetAllStatus()
{ {
var allStatusValues = Enum.GetValues(typeof(Status)).OfType<Status>(); var allStatusValues = Enum.GetValues(typeof(Status)).OfType<Status>();
foreach (var s in allStatusValues) foreach (var s in allStatusValues)
{ {
status.Add(s); allStatus.Add(s);
} }
OnPropertyChanged(nameof(AllStatus)); OnPropertyChanged(nameof(AllStatus));
} }
[RelayCommand]
private async Task GetToBeReadBooks() private async Task GetToBeReadBooks()
{ {
var result = await Model.GetBooksFromCollection(0, 1000); var result = await Model.GetBooksFromCollection(0, 1000);
@ -668,6 +392,7 @@ namespace ViewModels
OnPropertyChanged(nameof(ToBeReadBooks)); OnPropertyChanged(nameof(ToBeReadBooks));
} }
[RelayCommand]
private async Task GetFavoriteBooks() private async Task GetFavoriteBooks()
{ {
var result = await Model.GetFavoritesBooks(0, 1000); var result = await Model.GetFavoritesBooks(0, 1000);
@ -678,9 +403,10 @@ namespace ViewModels
{ {
favoriteBooks.Add(b); favoriteBooks.Add(b);
} }
OnPropertyChanged(nameof(AllFavoriteBooks)); OnPropertyChanged(nameof(FavoriteBooks));
} }
[RelayCommand]
private async Task AddToFavorites(BookVM bookVM) private async Task AddToFavorites(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);
@ -688,6 +414,7 @@ namespace ViewModels
await GetFavoriteBooks(); await GetFavoriteBooks();
} }
[RelayCommand]
private async Task RemoveFromFavorites(BookVM bookVM) private async Task RemoveFromFavorites(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);
@ -695,10 +422,11 @@ namespace ViewModels
await GetFavoriteBooks(); await GetFavoriteBooks();
} }
[RelayCommand]
private async Task CheckBookIsFavorite(BookVM bookVM) private async Task CheckBookIsFavorite(BookVM bookVM)
{ {
await GetFavoriteBooks(); await GetFavoriteBooks();
if (AllFavoriteBooks.Any(favoriteBook => favoriteBook.Id == bookVM.Id)) if (FavoriteBooks.Any(favoriteBook => favoriteBook.Id == bookVM.Id))
{ {
IsFavorite = true; IsFavorite = true;
OnPropertyChanged(nameof(IsFavorite)); OnPropertyChanged(nameof(IsFavorite));
@ -710,6 +438,7 @@ namespace ViewModels
} }
} }
[RelayCommand]
private async Task GetCurrentLoans() private async Task GetCurrentLoans()
{ {
var result = await Model.GetCurrentLoans(0, 1000); var result = await Model.GetCurrentLoans(0, 1000);
@ -718,11 +447,12 @@ namespace ViewModels
foreach (var l in someLoans.Select(l => new LoanVM(l))) foreach (var l in someLoans.Select(l => new LoanVM(l)))
{ {
currentLoans.Add(l); currentLoans.Add(l);
AllCurrentGroupedLoans = AllCurrentLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key); CurrentGroupedLoans = CurrentLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllCurrentLoans)); OnPropertyChanged(nameof(CurrentLoans));
} }
[RelayCommand]
private async Task GetPastLoans() private async Task GetPastLoans()
{ {
var result = await Model.GetPastLoans(0, 1000); var result = await Model.GetPastLoans(0, 1000);
@ -731,11 +461,12 @@ namespace ViewModels
foreach (var l in someLoans.Select(l => new LoanVM(l))) foreach (var l in someLoans.Select(l => new LoanVM(l)))
{ {
pastLoans.Add(l); pastLoans.Add(l);
AllPastGroupedLoans = AllPastLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key); PastGroupedLoans = PastLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllPastLoans)); OnPropertyChanged(nameof(PastLoans));
} }
[RelayCommand]
private async Task GetCurrentBorrowings() private async Task GetCurrentBorrowings()
{ {
var result = await Model.GetCurrentBorrowings(0, 1000); var result = await Model.GetCurrentBorrowings(0, 1000);
@ -744,11 +475,12 @@ namespace ViewModels
foreach (var b in someBorrowings.Select(b => new BorrowingVM(b))) foreach (var b in someBorrowings.Select(b => new BorrowingVM(b)))
{ {
currentBorrowings.Add(b); currentBorrowings.Add(b);
AllCurrentGroupedBorrowings = AllCurrentBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key); CurrentGroupedBorrowings = CurrentBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllCurrentBorrowings)); OnPropertyChanged(nameof(CurrentBorrowings));
} }
[RelayCommand]
private async Task GetPastBorrowings() private async Task GetPastBorrowings()
{ {
var result = await Model.GetPastBorrowings(0, 1000); var result = await Model.GetPastBorrowings(0, 1000);
@ -757,16 +489,17 @@ namespace ViewModels
foreach (var b in someBorrowings.Select(b => new BorrowingVM(b))) foreach (var b in someBorrowings.Select(b => new BorrowingVM(b)))
{ {
pastBorrowings.Add(b); pastBorrowings.Add(b);
AllPastGroupedBorrowings = AllPastBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key); PastGroupedBorrowings = PastBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllPastBorrowings)); OnPropertyChanged(nameof(PastBorrowings));
} }
[RelayCommand]
private async Task LendBook(ContactVM contactVM) private async Task LendBook(ContactVM contactVM)
{ {
var book = await Model.GetBookById(SelectedBook.Id); var book = await Model.GetBookById(SelectedBook.Id);
Model.Contact contact = new Model.Contact(); Model.Contact contact = new Model.Contact();
var resultContacts = await Model.GetContacts(Index, Count); var resultContacts = await Model.GetContacts(IndexPage, Count);
var allContacts = resultContacts.contacts; var allContacts = resultContacts.contacts;
foreach (var c in allContacts) foreach (var c in allContacts)
{ {
@ -781,9 +514,10 @@ namespace ViewModels
} }
} }
[RelayCommand]
private async Task GetContacts() private async Task GetContacts()
{ {
var result = await Model.GetContacts(Index, Count); var result = await Model.GetContacts(IndexPage, Count);
IEnumerable<Model.Contact> someContacts = result.contacts; IEnumerable<Model.Contact> someContacts = result.contacts;
someContacts = someContacts.OrderBy(c => c.FirstName); someContacts = someContacts.OrderBy(c => c.FirstName);
contacts.Clear(); contacts.Clear();
@ -791,12 +525,13 @@ namespace ViewModels
{ {
contacts.Add(c); contacts.Add(c);
} }
OnPropertyChanged(nameof(AllContacts)); OnPropertyChanged(nameof(Contacts));
} }
[RelayCommand]
private async Task AddContact() private async Task AddContact()
{ {
var result = await Model.GetContacts(Index, Count); var result = await Model.GetContacts(IndexPage, Count);
IEnumerable<Model.Contact> someContacts = result.contacts; IEnumerable<Model.Contact> someContacts = result.contacts;
int lastSequence = someContacts int lastSequence = someContacts
@ -820,7 +555,7 @@ namespace ViewModels
GivenLastName = null; GivenLastName = null;
await Model.AddContact(newContact); await Model.AddContact(newContact);
OnPropertyChanged(nameof(AllContacts)); OnPropertyChanged(nameof(Contacts));
} }
#endregion #endregion

@ -1,4 +1,4 @@
using PersonalMVVMToolkit; using CommunityToolkit.Mvvm.ComponentModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,13 +7,20 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class PublishDateVM : BaseViewModel [ObservableObject]
public partial class PublishDateVM
{ {
#region Properties #region Fields
[ObservableProperty]
private DateTime publishDate;
public DateTime PublishDate { get; set; } [ObservableProperty]
private int nbBooksWritten;
public int NbBooksWritten { get; set; } #endregion
#region Properties
#endregion #endregion

@ -1,5 +1,5 @@
using Model; using CommunityToolkit.Mvvm.ComponentModel;
using PersonalMVVMToolkit; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,28 +8,23 @@ using System.Threading.Tasks;
namespace ViewModels namespace ViewModels
{ {
public class RatingsVM [ObservableObject]
public partial class RatingsVM
{ {
#region Fields #region Fields
private int nbBooksWritten { get; set; } [ObservableProperty]
private int nbBooksWritten;
#endregion [ObservableProperty]
private float? average;
#region Properties
public float? Average { get; set; } [ObservableProperty]
private int count;
public int Count { get; set; } #endregion
public int NbBooksWritten #region Properties
{
get => nbBooksWritten;
set
{
nbBooksWritten = value;
}
}
#endregion #endregion

@ -7,9 +7,13 @@
<UseMaui>true</UseMaui> <UseMaui>true</UseMaui>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\PersonalMVVMToolkit\PersonalMVVMToolkit.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Loading…
Cancel
Save