dernier push

main
Najlae LAMBARAA 1 year ago
parent 6f4122a11a
commit ce072d1e89

@ -10,11 +10,8 @@ namespace View.ModelViewPage
{ {
public class ChampionsViewM public class ChampionsViewM
{ {
public Command NextPageCommand { get; private set; }
public Command PreviousPageCommand { get; }
public Command EditChampionCommand { get; } public Command EditChampionCommand { get; }
public ChampionManagerVM championManagerVm { get; } public ChampionManagerVM championManagerVm { get; }
public Command DeleteChampionCommand { get; private set; }
public ChampionsViewM(ChampionManagerVM championManager) public ChampionsViewM(ChampionManagerVM championManager)
@ -22,39 +19,12 @@ namespace View.ModelViewPage
{ {
championManagerVm = championManager; championManagerVm = championManager;
PushToDetailCommand = new Command<ChampionVm>(PushToDetail); PushToDetailCommand = new Command<ChampionVm>(PushToDetail);
DeleteChampionCommand = new Command<ChampionVm>(async (ChampionVm obj) => await championManagerVm.DeleteChampion(obj));
NextPageCommand = new Command(NextPage, CanExecuteNext);
PreviousPageCommand = new Command(PreviousPage, CanExecutePrevious);
AddChampionCommand = new Command(Addchampion); AddChampionCommand = new Command(Addchampion);
EditChampionCommand = new Command<ChampionVm>(EditChampion); EditChampionCommand = new Command<ChampionVm>(EditChampion);
} }
private void NextPage()
{
championManagerVm.Index++;
RefreshCanExecute();
}
private void PreviousPage()
{
championManagerVm.Index--;
RefreshCanExecute();
}
private bool CanExecutePrevious()
{
return championManagerVm.Index > 1;
}
private bool CanExecuteNext()
{
var val = (this.championManagerVm.Index) < this.championManagerVm.PageTotale;
return val;
}
void RefreshCanExecute()
{
PreviousPageCommand.ChangeCanExecute();
NextPageCommand.ChangeCanExecute();
}
public Command PushToDetailCommand { get; } public Command PushToDetailCommand { get; }
public Command AddChampionCommand { get; } public Command AddChampionCommand { get; }

@ -47,7 +47,7 @@
<SwipeItem Text="Supprimer" <SwipeItem Text="Supprimer"
BackgroundColor="Red" BackgroundColor="Red"
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ChampionsViewM}}, Path=DeleteChampionCommand} " Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ChampionsViewM}}, Path=championManagerVm.DeleteChampionCommand} "
CommandParameter="{Binding .}" /> CommandParameter="{Binding .}" />
</SwipeItems> </SwipeItems>
</SwipeView.RightItems> </SwipeView.RightItems>
@ -82,11 +82,11 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<HorizontalStackLayout > <HorizontalStackLayout >
<Button Text="L" HeightRequest="12 " WidthRequest="12" Padding="15" Command="{Binding PreviousPageCommand}"/> <Button Text="L" HeightRequest="12 " WidthRequest="12" Padding="15" Command="{Binding championManagerVm.PreviousPageCommand}"/>
<Button Text="R" HeightRequest="12 " Padding="10" WidthRequest="12" <Button Text="R" HeightRequest="12 " Padding="10" WidthRequest="12"
Command="{Binding NextPageCommand}" /> Command="{Binding championManagerVm.NextPageCommand}" />
</HorizontalStackLayout> </HorizontalStackLayout>

@ -25,7 +25,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="1" WidthRequest="420" HeightRequest="200" Margin="20"> <Grid Grid.Row="1" WidthRequest="420" HeightRequest="200" Margin="20">
<Image Source="{Binding ChampionVM.Image.Base64, Converter={StaticResource Base64ToImageConverter}}"></Image> <Image Source="{Binding ChampionVM.Image, Converter={StaticResource Base64ToImageConverter}}"></Image>
</Grid> </Grid>
<Grid Grid.Row="2" Margin="20"> <Grid Grid.Row="2" Margin="20">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

@ -12,7 +12,9 @@ namespace ViewModels
{ {
public ObservableCollection<ChampionVm> Champions { get; } public ObservableCollection<ChampionVm> Champions { get; }
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
public ICommand NextPageCommand { get; private set; } public Command NextPageCommand { get; private set; }
public Command PreviousPageCommand { get; }
public Command DeleChampionCommand { get; }
public ICommand DeleteChampionCommand { get; } public ICommand DeleteChampionCommand { get; }
public IDataManager DataManager public IDataManager DataManager
@ -31,10 +33,12 @@ namespace ViewModels
{ {
DataManager = dataManager; DataManager = dataManager;
Champions = new ObservableCollection<ChampionVm>(); Champions = new ObservableCollection<ChampionVm>();
DeleteChampionCommand = new Command<ChampionVm>(async (ChampionVm obj) => await DeleteChampion(obj));
LoadChampions(index, Count).ConfigureAwait(false); NextPageCommand = new Command(NextPage, CanExecuteNext);
PreviousPageCommand = new Command(PreviousPage, CanExecutePrevious);
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,7 +51,33 @@ namespace ViewModels
} }
} }
public int Index 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; get => index;
set set
@ -77,14 +107,6 @@ namespace ViewModels
OnPropertyChanged(); 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) protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
@ -102,15 +124,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)
{ {
if (editableChampionVM is null) return; if (editableChampionVM is null) return;

@ -42,13 +42,13 @@ namespace ViewModels
} }
} }
public LargeImage Image public string Image
{ {
get => Model.Image; get => Model.Image.Base64;
set set
{ {
if (model == null) return; if (model == null) return;
Model.Image = value; Model.Image.Base64 = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }

@ -16,7 +16,7 @@ namespace ViewModels
_bio = IsNew ? string.Empty : Model.Bio; _bio = IsNew ? string.Empty : Model.Bio;
icon = IsNew ? string.Empty : Model.Icon; icon = IsNew ? string.Empty : Model.Icon;
_name = IsNew ? string.Empty : Model.Name; _name = IsNew ? string.Empty : Model.Name;
image = IsNew ? string.Empty : Model.Image.Base64; image = IsNew ? string.Empty : Model.Image;
_classe = IsNew ? ChampionClass.Unknown : Model.Class; _classe = IsNew ? ChampionClass.Unknown : Model.Class;
ListClasses = Enum.GetValues<ChampionClass>().Where(c => c != ChampionClass.Unknown).ToArray(); ListClasses = Enum.GetValues<ChampionClass>().Where(c => c != ChampionClass.Unknown).ToArray();
} }
@ -113,7 +113,7 @@ namespace ViewModels
{ {
Model.Bio = Bio; Model.Bio = Bio;
Model.Icon = Icon; Model.Icon = Icon;
Model.Image.Base64 = Image; Model.Image = Image;
Model.Class = Class; Model.Class = Class;
} }
else else

Loading…
Cancel
Save