|
|
|
@ -3,29 +3,21 @@ using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class ChampionManagerVM : INotifyPropertyChanged
|
|
|
|
|
public partial class ChampionManagerVM : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public ObservableCollection<ChampionVm> Champions { get; }
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
public Command NextPageCommand { get; private set; }
|
|
|
|
|
public Command PreviousPageCommand { get; }
|
|
|
|
|
public Command DeleChampionCommand { get; }
|
|
|
|
|
public ICommand DeleteChampionCommand { get; }
|
|
|
|
|
|
|
|
|
|
public IDataManager DataManager
|
|
|
|
|
{
|
|
|
|
|
get => _dataManager;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_dataManager == value) return;
|
|
|
|
|
_dataManager = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
set => _dataManager = value;
|
|
|
|
|
}
|
|
|
|
|
private IDataManager _dataManager { get; set; }
|
|
|
|
|
|
|
|
|
@ -33,9 +25,6 @@ namespace ViewModels
|
|
|
|
|
{
|
|
|
|
|
DataManager = dataManager;
|
|
|
|
|
Champions = new ObservableCollection<ChampionVm>();
|
|
|
|
|
DeleteChampionCommand = new Command<ChampionVm>(async (ChampionVm obj) => await DeleteChampion(obj));
|
|
|
|
|
NextPageCommand = new Command(NextPage, CanExecuteNext);
|
|
|
|
|
PreviousPageCommand = new Command(PreviousPage, CanExecutePrevious);
|
|
|
|
|
|
|
|
|
|
LoadChampions(index, Count).ConfigureAwait(false);
|
|
|
|
|
PropertyChanged += ChampionManagerVM_PropertyChanged;
|
|
|
|
@ -51,42 +40,8 @@ namespace ViewModels
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NextPage()
|
|
|
|
|
{
|
|
|
|
|
Index++;
|
|
|
|
|
RefreshCanExecute();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void PreviousPage()
|
|
|
|
|
{
|
|
|
|
|
Index--;
|
|
|
|
|
RefreshCanExecute();
|
|
|
|
|
}
|
|
|
|
|
private bool CanExecutePrevious()
|
|
|
|
|
{
|
|
|
|
|
return Index > 1;
|
|
|
|
|
}
|
|
|
|
|
private bool CanExecuteNext()
|
|
|
|
|
{
|
|
|
|
|
var val = (this.Index) < this.PageTotale;
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
void RefreshCanExecute()
|
|
|
|
|
{
|
|
|
|
|
PreviousPageCommand.ChangeCanExecute();
|
|
|
|
|
NextPageCommand.ChangeCanExecute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Index
|
|
|
|
|
{
|
|
|
|
|
get => index;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (index == value) return;
|
|
|
|
|
index = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[NotifyCanExecuteChangedFor(nameof(PreviousPageCommand),nameof(NextPageCommand))]
|
|
|
|
|
private int index;
|
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
@ -94,23 +49,12 @@ namespace ViewModels
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
} = 5;
|
|
|
|
|
|
|
|
|
|
public int PageTotale { get { return this.total / Count + ((this.total % Count) > 0 ? 1 : 0); } }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private int total;
|
|
|
|
|
|
|
|
|
|
public int Total
|
|
|
|
|
{
|
|
|
|
|
get => total;
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
total = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadChampions(int index, int count)
|
|
|
|
|
{
|
|
|
|
@ -124,6 +68,7 @@ namespace ViewModels
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async void SaveChampion(EditChampionVm editableChampionVM, ChampionVm? championVM)
|
|
|
|
|
{
|
|
|
|
|
if (editableChampionVM is null) return;
|
|
|
|
@ -145,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()
|
|
|
|
|
{
|
|
|
|
@ -164,6 +128,8 @@ namespace ViewModels
|
|
|
|
|
OnPropertyChanged(nameof(PageTotale));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task DeleteChampion(ChampionVm champion)
|
|
|
|
|
{
|
|
|
|
|
if (champion is null) return;
|
|
|
|
|