Observable properties och RelayCommands införda
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using Common.Library;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
@ -20,6 +21,7 @@ public partial class ParticipantViewModel : ObservableObject
|
||||
_sharingService = sharingService;
|
||||
ParticipantObject = new Participant();
|
||||
ParticipantList = new ObservableCollection<Participant>();
|
||||
IsSaveCommandEnabled = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -33,6 +35,11 @@ public partial class ParticipantViewModel : ObservableObject
|
||||
private readonly IMethodSharingService<Participant> _sharingService;
|
||||
#endregion
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isSaveCommandEnabled;
|
||||
|
||||
|
||||
#region Get Method
|
||||
public ObservableCollection<Participant> Get()
|
||||
{
|
||||
@ -58,7 +65,12 @@ public partial class ParticipantViewModel : ObservableObject
|
||||
|
||||
return ParticipantObject;
|
||||
}
|
||||
public virtual bool Save()
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[RelayCommand(CanExecute = nameof(IsSaveCommandEnabled))]
|
||||
private async Task<bool> Save()
|
||||
{
|
||||
if (_Repository == null || ParticipantObject == null)
|
||||
{
|
||||
@ -70,8 +82,21 @@ public partial class ParticipantViewModel : ObservableObject
|
||||
{
|
||||
ParticipantObject = new Participant();
|
||||
this.Get();
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
return tmp != -1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteAsync(Participant pp)
|
||||
{
|
||||
Console.WriteLine($"Valt från ViewModel: {pp.FullName}");
|
||||
if (_Repository == null || pp == null || pp.ParticipantId <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var tmpTask = _Repository.Delete(pp);
|
||||
this.Get();
|
||||
Shell.Current.GoToAsync("..");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user