ADD : Avancement Prets & Emprunts (bug switch button)

commands-19-09
Lou BRODA 1 year ago
parent d683ae38ce
commit dccbbbf8a0

@ -1,5 +1,6 @@
using CommunityToolkit.Maui;
using LivreLand.View;
using LivreLand.View.ContentViews;
using LivreLand.ViewModel;
using Microsoft.Extensions.Logging;
using Model;
@ -30,8 +31,9 @@ public static class MauiProgram
.AddSingleton<FiltrageNoteView>()
.AddSingleton<ALirePlusTardView>()
.AddSingleton<StatutLectureView>()
.AddSingleton<EmpruntsPretsView>()
.AddSingleton<NavigatorVM>()
.AddSingleton<NavigatorVM>()
.AddSingleton<ILibraryManager, LibraryStub>()
.AddSingleton<IUserLibraryManager, UserLibraryStub>()
@ -45,7 +47,8 @@ public static class MauiProgram
.AddSingleton<FiltrageDateVM>()
.AddSingleton<FiltrageNoteVM>()
.AddSingleton<ALirePlusTardVM>()
.AddSingleton<StatutLectureVM>();
.AddSingleton<StatutLectureVM>()
.AddSingleton<EmpruntsPretsVM>();
#if DEBUG
builder.Logging.AddDebug();

@ -22,7 +22,7 @@ public partial class ALirePlusTardView : ContentPage
#endregion
#region Properties
#region Methods
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LivreLand.View.ContentViews.EmpruntsPretsButtonView">
x:Class="LivreLand.View.ContentViews.EmpruntsPretsButtonView"
x:Name="this">
<Grid>
<Grid BindingContext="{x:Reference this}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*"/>
@ -17,18 +18,18 @@
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Button x:Name="pretsClicked"
Text="Prêts"
<Button Text="Prêts"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}"
Clicked="OnPretsClicked"
BackgroundColor="{Binding PretButtonBackgroundColor}"
IsEnabled="{Binding PretButtonIsEnabled}"
Command="{Binding PretsButtonCommand}"
Margin="2"
Grid.Column="0"/>
<Button x:Name="empruntsButton"
Text="Emprunts"
<Button Text="Emprunts"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
BackgroundColor="Transparent"
Clicked="OnEmpruntsClicked"
BackgroundColor="{Binding EmpruntButtonBackgroundColor}"
IsEnabled="{Binding EmpruntButtonIsEnabled}"
Command="{Binding EmpruntsButtonCommand}"
Margin="2"
Grid.Column="1"/>
</Grid>

@ -1,46 +1,61 @@
using LivreLand.ViewModel;
using System.Windows.Input;
namespace LivreLand.View.ContentViews;
public partial class EmpruntsPretsButtonView : ContentView
{
public EmpruntsPretsButtonView()
{
InitializeComponent();
}
#region Properties
public void OnPretsClicked(object sender, EventArgs e)
{
if (App.Current.PlatformAppTheme == AppTheme.Light)
{
pretsClicked.BackgroundColor = Colors.Transparent;
pretsClicked.IsEnabled = false;
empruntsButton.BackgroundColor = Colors.White;
empruntsButton.IsEnabled = true;
}
else
{
pretsClicked.BackgroundColor = Colors.Transparent;
pretsClicked.IsEnabled = false;
empruntsButton.BackgroundColor = Colors.Black;
empruntsButton.IsEnabled = true;
}
}
public static readonly BindableProperty PretButtonBackgroundColorProperty = BindableProperty.Create(nameof(PretButtonBackgroundColor), typeof(Color), typeof(EmpruntsPretsButtonView));
public Color PretButtonBackgroundColor
{
get => (Color)GetValue(EmpruntsPretsButtonView.PretButtonBackgroundColorProperty);
set => SetValue(EmpruntsPretsButtonView.PretButtonBackgroundColorProperty, value);
}
public static readonly BindableProperty PretButtonIsEnabledProperty = BindableProperty.Create(nameof(PretButtonIsEnabled), typeof(bool), typeof(EmpruntsPretsButtonView));
public bool PretButtonIsEnabled
{
get => (bool)GetValue(EmpruntsPretsButtonView.PretButtonIsEnabledProperty);
set => SetValue(EmpruntsPretsButtonView.PretButtonIsEnabledProperty, value);
}
public void OnEmpruntsClicked(object sender, EventArgs e)
public static readonly BindableProperty PretsButtonCommandProperty = BindableProperty.Create(nameof(PretsButtonCommand), typeof(ICommand), typeof(EmpruntsPretsButtonView));
public ICommand PretsButtonCommand
{
if (App.Current.PlatformAppTheme == AppTheme.Light)
{
pretsClicked.BackgroundColor = Colors.White;
pretsClicked.IsEnabled = true;
empruntsButton.BackgroundColor = Colors.Transparent;
empruntsButton.IsEnabled = false;
}
else
{
pretsClicked.BackgroundColor = Colors.Black;
pretsClicked.IsEnabled = true;
empruntsButton.BackgroundColor = Colors.Transparent;
empruntsButton.IsEnabled = false;
}
get { return (ICommand)GetValue(PretsButtonCommandProperty); }
set { SetValue(PretsButtonCommandProperty, value); }
}
public static readonly BindableProperty EmpruntButtonBackgroundColorProperty = BindableProperty.Create(nameof(EmpruntButtonBackgroundColor), typeof(Color), typeof(EmpruntsPretsButtonView));
public Color EmpruntButtonBackgroundColor
{
get => (Color)GetValue(EmpruntsPretsButtonView.EmpruntButtonBackgroundColorProperty);
set => SetValue(EmpruntsPretsButtonView.EmpruntButtonBackgroundColorProperty, value);
}
public static readonly BindableProperty EmpruntButtonIsEnabledProperty = BindableProperty.Create(nameof(EmpruntButtonIsEnabled), typeof(bool), typeof(EmpruntsPretsButtonView));
public bool EmpruntButtonIsEnabled
{
get => (bool)GetValue(EmpruntsPretsButtonView.EmpruntButtonIsEnabledProperty);
set => SetValue(EmpruntsPretsButtonView.EmpruntButtonIsEnabledProperty, value);
}
public static readonly BindableProperty EmpruntsButtonCommandProperty = BindableProperty.Create(nameof(EmpruntsButtonCommand), typeof(ICommand), typeof(EmpruntsPretsButtonView));
public ICommand EmpruntsButtonCommand
{
get { return (ICommand)GetValue(EmpruntsButtonCommandProperty); }
set { SetValue(EmpruntsButtonCommandProperty, value); }
}
#endregion
#region Constructor
public EmpruntsPretsButtonView()
{
InitializeComponent();
}
#endregion
}

@ -2,7 +2,8 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.EmpruntsPretsView"
Title="EmpruntsPretsView">
@ -20,37 +21,21 @@
HeaderPlusButtonVisible="True"
HeaderSwitchButtonVisible="True"
Grid.Row="0"/>
<contentView:EmpruntsPretsButtonView Grid.Row="2"/>
<contentView:EmpruntsPretsButtonView Grid.Row="2"
PretButtonBackgroundColor="{Binding EmpruntsPretsVM.PretButtonBackgroundColor}"
PretButtonIsEnabled="{Binding EmpruntsPretsVM.PretButtonIsEnabled}"
PretsButtonCommand="{Binding EmpruntsPretsVM.PretsButtonCommand}"
EmpruntButtonBackgroundColor="{Binding EmpruntsPretsVM.EmpruntButtonBackgroundColor}"
EmpruntButtonIsEnabled="{Binding EmpruntsPretsVM.EmpruntButtonIsEnabled}"
EmpruntsButtonCommand="{Binding EmpruntsPretsVM.EmpruntsButtonCommand}"/>
<ScrollView Grid.Row="4">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="10"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="40"/>
<RowDefinition Height="10"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="Antoine"
VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/>
</Grid>
<CollectionView ItemsSource="{Binding AntoineBooks}"
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentLoans}"
SelectionMode="Single"
SelectionChanged="OnSelectionChanged"
Grid.Row="2">
IsVisible="{Binding EmpruntsPretsVM.PretCollectionIsVisible}">
<CollectionView.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="viewModel:LoanVM">
<VerticalStackLayout Margin="10"
Spacing="20">
<VisualStateManager.VisualStateGroups x:Name="SelectionStates">
@ -89,7 +74,7 @@
Stroke="{StaticResource Gray}"
StrokeShape="RoundRectangle 3"
StrokeThickness="3">
<Image Source="couverture_la_horde_du_contrevent.png"
<Image Source="{Binding Book.ImageSmall}"
Aspect="AspectFill"
Grid.Column="0"
Grid.RowSpan="5"/>
@ -101,15 +86,15 @@
Margin="0,97,20,0"
VerticalOptions="End"/>
</Grid>
<Label Text="{Binding Title}"
<Label Text="{Binding Book.Title}"
Style="{StaticResource MasterTitleBookText}"
Grid.Column="2"
Grid.Row="0"/>
<Label Text="{Binding Author}"
<Label Text="Author"
Style="{StaticResource MasterAuthorBookText}"
Grid.Column="2"
Grid.Row="1"/>
<Label Text="{Binding State}"
<Label Text="{Binding Book.Status}"
Style="{StaticResource MasterStateBookText}"
Grid.Column="2"
Grid.Row="2"/>
@ -121,25 +106,12 @@
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="Audrey Pouclet"
VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/>
</Grid>
<CollectionView ItemsSource="{Binding AudreyPoucletBooks}"
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentBorrowings}"
SelectionMode="Single"
SelectionChanged="OnSelectionChanged"
Grid.Row="6">
IsVisible="{Binding EmpruntsPretsVM.EmpruntCollectionIsVisible}">
<CollectionView.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="viewModel:BorrowingVM">
<VerticalStackLayout Margin="10"
Spacing="20">
<VisualStateManager.VisualStateGroups x:Name="SelectionStates">
@ -178,7 +150,7 @@
Stroke="{StaticResource Gray}"
StrokeShape="RoundRectangle 3"
StrokeThickness="3">
<Image Source="couverture_la_horde_du_contrevent.png"
<Image Source="{Binding Book.ImageSmall}"
Aspect="AspectFill"
Grid.Column="0"
Grid.RowSpan="5"/>
@ -190,15 +162,15 @@
Margin="0,97,20,0"
VerticalOptions="End"/>
</Grid>
<Label Text="{Binding Title}"
<Label Text="{Binding Book.Title}"
Style="{StaticResource MasterTitleBookText}"
Grid.Column="2"
Grid.Row="0"/>
<Label Text="{Binding Author}"
<Label Text="Author"
Style="{StaticResource MasterAuthorBookText}"
Grid.Column="2"
Grid.Row="1"/>
<Label Text="{Binding State}"
<Label Text="{Binding Book.Status}"
Style="{StaticResource MasterStateBookText}"
Grid.Column="2"
Grid.Row="2"/>

@ -1,27 +1,41 @@
using LivreLand.Model;
using LivreLand.ViewModel;
namespace LivreLand.View;
public partial class EmpruntsPretsView : ContentPage
{
public List<BookModel> AntoineBooks { get; set; } = new List<BookModel>()
{
new BookModel("The Wake","Scott Snyder","Terminé", 0),
};
#region Properties
public List<BookModel> AudreyPoucletBooks { get; set; } = new List<BookModel>()
{
new BookModel("Les feux de Cibola","James S. A. Corey","Terminé", 0),
};
public EmpruntsPretsVM EmpruntsPretsVM { get; set; }
#endregion
#region Constructor
public EmpruntsPretsView()
public EmpruntsPretsView(EmpruntsPretsVM empruntsPretsVM)
{
BindingContext = this;
EmpruntsPretsVM = empruntsPretsVM;
InitializeComponent();
BindingContext = this;
}
#endregion
#region Methods
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView());
}
protected override void OnAppearing()
{
base.OnAppearing();
EmpruntsPretsVM.Manager.GetCurrentLoansCommand.Execute(null);
EmpruntsPretsVM.Manager.GetCurrentBorrowingsCommand.Execute(null);
}
#endregion
}

@ -15,8 +15,6 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<view:HeaderPage HeaderTitle="Tous"
@ -37,23 +35,26 @@
<RowDefinition Height="10"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="Alain Damasio"
VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/>
</Grid>
<CollectionView ItemsSource="{Binding TousVM.Manager.AllBooks}"
SelectionMode="Single"
SelectionChanged="OnSelectionChanged"
Grid.Row="2">
<CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="viewModel:BookVM">
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="Alain Damasio"
VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/>
</Grid>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:BookVM">
<VerticalStackLayout Margin="10"
@ -119,7 +120,8 @@
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:AuthorVM">
<Label Text="{Binding Name}"
Style="{StaticResource MasterAuthorBookText}"/>
Style="{StaticResource MasterAuthorBookText}"
Margin="5,0,5,0"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
@ -135,19 +137,6 @@
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="Cixin Liu"
VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/>
</Grid>
<Grid Grid.Row="6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>

@ -0,0 +1,129 @@
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels;
namespace LivreLand.ViewModel
{
public class EmpruntsPretsVM : BaseViewModel
{
#region Fields
private Color pretButtonBackgroundColor = Colors.White;
private bool pretButtonIsEnabled = true;
private Color empruntButtonBackgroundColor = Colors.Transparent;
private bool empruntButtonIsEnabled = false;
private bool pretCollectionIsVisible = true;
private bool empruntCollectionIsVisible = false;
#endregion
#region Properties
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
public Color PretButtonBackgroundColor
{
get => pretButtonBackgroundColor;
set => pretButtonBackgroundColor = value;
}
public bool PretButtonIsEnabled
{
get => pretButtonIsEnabled;
set => pretButtonIsEnabled = value;
}
public Color EmpruntButtonBackgroundColor
{
get => empruntButtonBackgroundColor;
set => empruntButtonBackgroundColor = value;
}
public bool EmpruntButtonIsEnabled
{
get => empruntButtonIsEnabled;
set => empruntButtonIsEnabled = value;
}
public bool EmpruntCollectionIsVisible
{
get => empruntCollectionIsVisible;
set => empruntCollectionIsVisible = value;
}
public bool PretCollectionIsVisible
{
get => pretCollectionIsVisible;
set => pretCollectionIsVisible = value;
}
public ICommand PretsButtonCommand { get; private set; }
public ICommand EmpruntsButtonCommand { get; private set; }
#endregion
#region Constructor
public EmpruntsPretsVM(NavigatorVM navigatorVM, ManagerVM managerVM)
{
Navigator = navigatorVM;
Manager = managerVM;
PretsButtonCommand = new RelayCommand(() => PretsButtonClicked());
EmpruntsButtonCommand = new RelayCommand(() => EmpruntsButtonClicked());
}
#endregion
#region Methods
public void PretsButtonClicked()
{
if (App.Current.PlatformAppTheme == AppTheme.Light)
{
pretButtonBackgroundColor = Colors.Transparent;
pretButtonIsEnabled = false;
empruntButtonBackgroundColor = Colors.White;
empruntButtonIsEnabled = true;
}
else
{
pretButtonBackgroundColor = Colors.Transparent;
pretButtonIsEnabled = false;
empruntButtonBackgroundColor = Colors.Black;
empruntButtonIsEnabled = true;
}
pretCollectionIsVisible = false;
empruntCollectionIsVisible = true;
}
public void EmpruntsButtonClicked()
{
if (App.Current.PlatformAppTheme == AppTheme.Light)
{
pretButtonBackgroundColor = Colors.White;
pretButtonIsEnabled = true;
empruntButtonBackgroundColor = Colors.Transparent;
empruntButtonIsEnabled = false;
}
else
{
pretButtonBackgroundColor = Colors.Black;
pretButtonIsEnabled = true;
empruntButtonBackgroundColor = Colors.Transparent;
empruntButtonIsEnabled = false;
}
pretCollectionIsVisible = true;
empruntCollectionIsVisible = false;
}
#endregion
}
}

@ -0,0 +1,58 @@
using Model;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels
{
public class BorrowingVM : BaseViewModel<Borrowing>
{
#region Fields
#endregion
#region Properties
public string Id
{
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
}
public BookVM Book
{
get => new BookVM(Model.Book);
}
public ContactVM Owner
{
get => new ContactVM(Model.Owner);
}
public DateTime BorrowedAt
{
get => Model.BorrowedAt;
set => SetProperty(Model.BorrowedAt, value, v => Model.BorrowedAt = value);
}
public DateTime? ReturnedAt
{
get => Model.ReturnedAt;
set => SetProperty(Model.ReturnedAt, value, v => Model.ReturnedAt = value);
}
#endregion
#region Constructor
public BorrowingVM(Borrowing b) : base(b)
{
}
#endregion
}
}

@ -0,0 +1,48 @@
using Model;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels
{
public class ContactVM : BaseViewModel<Model.Contact>
{
#region Fields
#endregion
#region Properties
public string Id
{
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
}
public string FirstName
{
get => Model.FirstName;
set => SetProperty(Model.FirstName, value, v => Model.FirstName = value);
}
public string LastName
{
get => Model.LastName;
set => SetProperty(Model.LastName, value, v => Model.LastName = value);
}
#endregion
#region Constructor
public ContactVM(Model.Contact c) : base(c)
{
}
#endregion
}
}

@ -0,0 +1,58 @@
using Model;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels
{
public class LoanVM : BaseViewModel<Loan>
{
#region Fields
#endregion
#region Properties
public string Id
{
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
}
public BookVM Book
{
get => new BookVM(Model.Book);
}
public ContactVM Loaner
{
get => new ContactVM(Model.Loaner);
}
public DateTime LoanedAt
{
get => Model.LoanedAt;
set => SetProperty(Model.LoanedAt, value, v => Model.LoanedAt = value);
}
public DateTime? ReturnedAt
{
get => Model.ReturnedAt;
set => SetProperty(Model.ReturnedAt, value, v => Model.ReturnedAt = value);
}
#endregion
#region Constructor
public LoanVM(Loan l) : base(l)
{
}
#endregion
}
}

@ -1,6 +1,7 @@
using Model;
using PersonalMVVMToolkit;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
namespace ViewModels
@ -15,6 +16,10 @@ namespace ViewModels
private readonly ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>();
private readonly ObservableCollection<RatingsVM> ratings = new ObservableCollection<RatingsVM>();
private readonly ObservableCollection<BookVM> toBeReadBooks = new ObservableCollection<BookVM>();
private readonly ObservableCollection<LoanVM> currentLoans = new ObservableCollection<LoanVM>();
private readonly ObservableCollection<LoanVM> pastLoans = new ObservableCollection<LoanVM>();
private readonly ObservableCollection<BorrowingVM> pastBorrowings = new ObservableCollection<BorrowingVM>();
private readonly ObservableCollection<BorrowingVM> currentBorrowings = new ObservableCollection<BorrowingVM>();
private int index;
private long nbBooks;
@ -47,6 +52,26 @@ namespace ViewModels
get => toBeReadBooks;
}
public ObservableCollection<LoanVM> AllCurrentLoans
{
get => currentLoans;
}
public ObservableCollection<LoanVM> AllPastLoans
{
get => pastLoans;
}
public ObservableCollection<BorrowingVM> AllCurrentBorrowings
{
get => currentBorrowings;
}
public ObservableCollection<BorrowingVM> AllPastBorrowings
{
get => pastBorrowings;
}
public AuthorVM SelectedAuthor { get; private set; }
public string SearchTitle { get; private set; }
@ -88,6 +113,14 @@ namespace ViewModels
public ICommand GetToBeReadBooksCommand { 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; }
#endregion
#region Constructor
@ -102,6 +135,10 @@ namespace ViewModels
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
GetPastLoansCommand = new RelayCommand(() => GetPastLoans());
GetCurrentBorrowingsCommand = new RelayCommand(() => GetCurrentBorrowings());
GetPastBorrowingsCommand = new RelayCommand(() => GetPastBorrowings());
//GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book)));
}
@ -236,6 +273,54 @@ namespace ViewModels
}
}
private async Task GetCurrentLoans()
{
var result = await Model.GetCurrentLoans(0, 20);
IEnumerable<Loan> someLoans = result.loans;
currentLoans.Clear();
foreach (var l in someLoans.Select(l => new LoanVM(l)))
{
currentLoans.Add(l);
}
OnPropertyChanged(nameof(AllCurrentLoans));
}
private async Task GetPastLoans()
{
var result = await Model.GetPastLoans(0, 20);
IEnumerable<Loan> someLoans = result.loans;
pastLoans.Clear();
foreach (var l in someLoans.Select(l => new LoanVM(l)))
{
pastLoans.Add(l);
}
OnPropertyChanged(nameof(AllPastLoans));
}
private async Task GetCurrentBorrowings()
{
var result = await Model.GetCurrentBorrowings(0, 20);
IEnumerable<Borrowing> someBorrowings = result.borrowings;
currentBorrowings.Clear();
foreach (var b in someBorrowings.Select(b => new BorrowingVM(b)))
{
currentBorrowings.Add(b);
}
OnPropertyChanged(nameof(AllCurrentBorrowings));
}
private async Task GetPastBorrowings()
{
var result = await Model.GetPastBorrowings(0, 20);
IEnumerable<Borrowing> someBorrowings = result.borrowings;
pastBorrowings.Clear();
foreach (var b in someBorrowings.Select(b => new BorrowingVM(b)))
{
pastBorrowings.Add(b);
}
OnPropertyChanged(nameof(AllPastBorrowings));
}
#endregion
}
}
Loading…
Cancel
Save