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>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="6.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibraryDTO\LibraryDTO.csproj" />
</ItemGroup>

@ -7,6 +7,8 @@
</PropertyGroup>
<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" />
</ItemGroup>

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

@ -54,13 +54,13 @@
<ItemGroup>
<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" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\PersonalMVVMToolkit\PersonalMVVMToolkit.csproj" />
<ProjectReference Include="..\Stub\Stub.csproj" />
<ProjectReference Include="..\ViewModels\ViewModels.csproj" />
</ItemGroup>

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

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

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

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

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

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

@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,71 +12,29 @@ using ViewModels;
namespace LivreLand.ViewModel
{
public class DetailsLivreVM : BaseViewModel
[ObservableObject]
public partial class DetailsLivreVM
{
#region Fields
private bool isPickerVisible = false;
private string addFavorisButtonText;
#endregion
#region Properties
public ManagerVM Manager { get; private set; }
[ObservableProperty]
private NavigatorVM navigator;
public NavigatorVM Navigator { get; private set; }
[ObservableProperty]
private ManagerVM manager;
public BookVM Book { get; private set; }
[ObservableProperty]
private BookVM book;
public bool IsPickerVisible
{
get => isPickerVisible;
set
{
if (isPickerVisible != value)
{
isPickerVisible = value;
OnPropertyChanged(nameof(IsPickerVisible));
}
}
}
public string AddFavorisButtonText
{
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; }
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
@ -86,30 +45,27 @@ namespace LivreLand.ViewModel
Manager = managerVM;
Navigator = navigatorVM;
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
#region Methods
[RelayCommand]
private void BackButton()
{
Navigator.PopupBackButtonNavigationCommand.Execute(null);
}
[RelayCommand]
private void ShowPicker()
{
Manager.GetAllStatusCommand.Execute(null);
Manager.SelectedStatus = this.Book.Status;
Manager.SelectedStatus = Book.Status;
IsPickerVisible = true;
}
[RelayCommand]
private async Task AddRemoveBookToFavorites(BookVM bookVM)
{
Manager.CheckBookIsFavoriteCommand.Execute(bookVM);
@ -139,6 +95,7 @@ namespace LivreLand.ViewModel
}
}
[RelayCommand]
private async Task AddBookToReadList(BookVM bookVM)
{
Manager.UpdateToBeReadBookCommand.Execute(bookVM);
@ -150,6 +107,7 @@ namespace LivreLand.ViewModel
Navigator.NavigationCommand.Execute("/later");
}
[RelayCommand]
private void LoanBook(BookVM bookVM)
{
Manager.SelectedBook = bookVM;
@ -157,6 +115,7 @@ namespace LivreLand.ViewModel
Navigator.NavigationCommand.Execute("contacts");
}
[RelayCommand]
private async Task RemoveBook(BookVM 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 PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,111 +12,39 @@ using ViewModels;
namespace LivreLand.ViewModel
{
public class EmpruntsPretsVM : BaseViewModel
[ObservableObject]
public partial class EmpruntsPretsVM
{
#region Fields
[ObservableProperty]
private NavigatorVM navigator;
[ObservableProperty]
private ManagerVM manager;
[ObservableProperty]
private Color pretButtonBackgroundColor = Colors.White;
[ObservableProperty]
private bool pretButtonIsEnabled = true;
[ObservableProperty]
private Color empruntButtonBackgroundColor = Colors.Transparent;
[ObservableProperty]
private bool empruntButtonIsEnabled = false;
[ObservableProperty]
private bool pretCollectionIsVisible = true;
[ObservableProperty]
private bool empruntCollectionIsVisible = false;
#endregion
#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
#region Constructor
@ -124,21 +53,18 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
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
#region Methods
[RelayCommand]
private void OnSelectionLoanChanged(LoanVM loanVM)
{
if (loanVM != null)
{
foreach (var b in Manager.AllCurrentLoans)
foreach (var b in Manager.CurrentLoans)
{
if (b.Book.Id == loanVM.Book.Id)
{
@ -150,11 +76,12 @@ namespace LivreLand.ViewModel
}
}
[RelayCommand]
private void OnSelectionBorrowingChanged(BorrowingVM borrowingVM)
{
if (borrowingVM != null)
{
foreach (var b in Manager.AllCurrentBorrowings)
foreach (var b in Manager.CurrentBorrowings)
{
if (b.Book.Id == borrowingVM.Book.Id)
{
@ -166,6 +93,7 @@ namespace LivreLand.ViewModel
}
}
[RelayCommand]
public void PretsButtonClicked()
{
if (App.Current.PlatformAppTheme == AppTheme.Light)
@ -186,6 +114,7 @@ namespace LivreLand.ViewModel
EmpruntCollectionIsVisible = true;
}
[RelayCommand]
public void EmpruntsButtonClicked()
{
if (App.Current.PlatformAppTheme == AppTheme.Light)

@ -1,4 +1,4 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
@ -8,13 +8,20 @@ using ViewModels;
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

@ -1,4 +1,5 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,15 +10,20 @@ using ViewModels;
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
@ -27,13 +33,13 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
NavigateAuthorPageCommand = new RelayCommand(() => NavigateAuthorPage());
}
#endregion
#region Methods
[RelayCommand]
private void NavigateAuthorPage()
{
Manager.GetBooksByAuthorCommand.Execute(null);

@ -1,4 +1,5 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,15 +10,20 @@ using ViewModels;
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
@ -27,13 +33,13 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
NavigateDatePageCommand = new RelayCommand(() => NavigateDatePage());
}
#endregion
#region Methods
[RelayCommand]
private void NavigateDatePage()
{
Manager.GetBooksByDateCommand.Execute(null);

@ -1,4 +1,5 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,15 +10,20 @@ using ViewModels;
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
@ -27,13 +33,13 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
NavigateRatingPageCommand = new RelayCommand(() => NavigateRatingPage());
}
#endregion
#region Methods
[RelayCommand]
private void NavigateRatingPage()
{
Manager.GetBooksByRatingCommand.Execute(null);

@ -1,4 +1,6 @@
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using LivreLand.View.ContentViews;
using System;
@ -10,14 +12,14 @@ using System.Windows.Input;
namespace LivreLand.ViewModel
{
public class NavigatorVM
[ObservableObject]
public partial class NavigatorVM
{
#region Properties
#region Fields
#endregion
public ICommand NavigationCommand { get; }
public ICommand PopupHomePlusNavigationCommand { get; }
public ICommand PopupISBNNavigationCommand { get; }
public ICommand PopupBackButtonNavigationCommand { get; }
#region Properties
#endregion
@ -25,17 +27,37 @@ namespace LivreLand.ViewModel
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
#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
}
}

@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Model;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,15 +12,20 @@ using ViewModels;
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
@ -29,13 +35,13 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
AddBookCommand = new RelayCommand<string>((text) => AddBook(text));
}
#endregion
#region Methods
[RelayCommand]
private async Task AddBook(string entryText)
{
Manager.AddBookCommand.Execute(entryText);

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

@ -1,5 +1,6 @@
using LivreLand.View;
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,15 +11,20 @@ using ViewModels;
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
@ -28,13 +34,13 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
}
#endregion
#region Methods
[RelayCommand]
private void OnSelectionChanged(BookVM bookVM)
{
if (bookVM != null)

@ -1,5 +1,6 @@
using LivreLand.View;
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LivreLand.View;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,15 +11,20 @@ using ViewModels;
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
@ -28,13 +34,13 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
}
#endregion
#region Methods
[RelayCommand]
private void OnSelectionChanged(BookVM bookVM)
{
if (bookVM != null)

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,4 +1,4 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
@ -7,13 +7,20 @@ using System.Threading.Tasks;
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

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

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

Loading…
Cancel
Save