|
|
@ -3,27 +3,21 @@ using System.Collections.ObjectModel;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Windows.Input;
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
using Model;
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ViewModels
|
|
|
|
namespace ViewModels
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ChampionManagerVM : INotifyPropertyChanged
|
|
|
|
public partial class ChampionManagerVM : ObservableObject
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public ObservableCollection<ChampionVm> Champions { get; }
|
|
|
|
public ObservableCollection<ChampionVm> Champions { get; }
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
|
|
public ICommand NextPageCommand { get; private set; }
|
|
|
|
|
|
|
|
public ICommand DeleteChampionCommand { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IDataManager DataManager
|
|
|
|
public IDataManager DataManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => _dataManager;
|
|
|
|
get => _dataManager;
|
|
|
|
set
|
|
|
|
set => _dataManager = value;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_dataManager == value) return;
|
|
|
|
|
|
|
|
_dataManager = value;
|
|
|
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private IDataManager _dataManager { get; set; }
|
|
|
|
private IDataManager _dataManager { get; set; }
|
|
|
|
|
|
|
|
|
|
|
@ -34,7 +28,6 @@ namespace ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
LoadChampions(index, Count).ConfigureAwait(false);
|
|
|
|
LoadChampions(index, Count).ConfigureAwait(false);
|
|
|
|
PropertyChanged += ChampionManagerVM_PropertyChanged;
|
|
|
|
PropertyChanged += ChampionManagerVM_PropertyChanged;
|
|
|
|
PropertyChanged += ChampionManager_PropertyChanged;
|
|
|
|
|
|
|
|
Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
|
|
|
|
Total = this.DataManager.ChampionsMgr.GetNbItems().Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -47,16 +40,8 @@ namespace ViewModels
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int Index
|
|
|
|
[ObservableProperty]
|
|
|
|
{
|
|
|
|
[NotifyCanExecuteChangedFor(nameof(PreviousPageCommand),nameof(NextPageCommand))]
|
|
|
|
get => index;
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (index == value) return;
|
|
|
|
|
|
|
|
index = value;
|
|
|
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int index;
|
|
|
|
private int index;
|
|
|
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
public int Count
|
|
|
@ -64,31 +49,12 @@ namespace ViewModels
|
|
|
|
get;
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
set;
|
|
|
|
} = 5;
|
|
|
|
} = 5;
|
|
|
|
|
|
|
|
|
|
|
|
public int PageTotale { get { return this.total / Count + ((this.total % Count) > 0 ? 1 : 0); } }
|
|
|
|
public int PageTotale { get { return this.total / Count + ((this.total % Count) > 0 ? 1 : 0); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
private int total;
|
|
|
|
private int total;
|
|
|
|
|
|
|
|
|
|
|
|
public int Total
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get => total;
|
|
|
|
|
|
|
|
private set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
total = value;
|
|
|
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public int nombrepage(int GetNbItems, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int result = GetNbItems / count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result < 0) return result + 1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task LoadChampions(int index, int count)
|
|
|
|
private async Task LoadChampions(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -102,14 +68,6 @@ namespace ViewModels
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void ChampionManager_PropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (e.PropertyName == nameof(Index))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Champions.Clear();
|
|
|
|
|
|
|
|
await LoadChampions(Index, Count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async void SaveChampion(EditChampionVm editableChampionVM, ChampionVm? championVM)
|
|
|
|
public async void SaveChampion(EditChampionVm editableChampionVM, ChampionVm? championVM)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -132,8 +90,27 @@ namespace ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand(CanExecute =nameof(CanExecuteNext))]
|
|
|
|
|
|
|
|
private void NextPage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Index++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand(CanExecute =nameof(CanExecutePrevious))]
|
|
|
|
|
|
|
|
private void PreviousPage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Index--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CanExecutePrevious()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Index > 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CanExecuteNext()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var val = (this.Index) < this.PageTotale;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void updatePagination()
|
|
|
|
private async void updatePagination()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -151,6 +128,8 @@ namespace ViewModels
|
|
|
|
OnPropertyChanged(nameof(PageTotale));
|
|
|
|
OnPropertyChanged(nameof(PageTotale));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
public async Task DeleteChampion(ChampionVm champion)
|
|
|
|
public async Task DeleteChampion(ChampionVm champion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (champion is null) return;
|
|
|
|
if (champion is null) return;
|
|
|
|