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("..");
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
using Common.Library;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using GreadyPoang.DataLayer;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using GreadyPoang.Services;
|
||||
@ -98,8 +99,8 @@ public partial class RoundRunningViewModel : ObservableObject
|
||||
return RoundElements;
|
||||
}
|
||||
|
||||
|
||||
public void StoreAndHandlePoints()
|
||||
[RelayCommand]
|
||||
private void StoreAndHandlePointsAsync()
|
||||
{
|
||||
var game = _roundsRepo.Get(BuilderObject.GameRoundId).GetAwaiter().GetResult();
|
||||
var regNr = RoundElements.Count > 0 ? RoundElements.Max(e => e.GameRoundRegNr) + 1 : 1;
|
||||
@ -147,6 +148,8 @@ public partial class RoundRunningViewModel : ObservableObject
|
||||
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
|
||||
}
|
||||
TriggerRebuild();
|
||||
Shell.Current.GoToAsync("..").GetAwaiter().GetResult();
|
||||
|
||||
}
|
||||
|
||||
private int nextPlayerElement()
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Common.Library;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using GreadyPoang.DataLayer;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using GreadyPoang.Services;
|
||||
@ -39,6 +40,7 @@ public partial class RoundStartingViewModel : ObservableObject
|
||||
private readonly ICombinedRepository _combined;
|
||||
private readonly IObjectMessageService _objectMessage;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private Participant selectedItem;
|
||||
partial void OnSelectedItemChanged(Participant value)
|
||||
@ -108,6 +110,7 @@ public partial class RoundStartingViewModel : ObservableObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Get Method
|
||||
public ObservableCollection<RoundBuilderGroup> Get()
|
||||
{
|
||||
@ -167,7 +170,9 @@ public partial class RoundStartingViewModel : ObservableObject
|
||||
|
||||
return GameRoundObject;
|
||||
}
|
||||
public virtual bool Save()
|
||||
|
||||
[RelayCommand]
|
||||
public async Task<bool> SaveAsync()
|
||||
{
|
||||
if (_roundsRepo == null || GameRoundObject == null)
|
||||
{
|
||||
@ -180,11 +185,13 @@ public partial class RoundStartingViewModel : ObservableObject
|
||||
GameRoundObject = new GameRound();
|
||||
RoundElements.Clear();
|
||||
this.Get();
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void Rensa()
|
||||
[RelayCommand]
|
||||
private async Task RensaAsync()
|
||||
{
|
||||
foreach (var element in RoundElements)
|
||||
{
|
||||
@ -192,22 +199,31 @@ public partial class RoundStartingViewModel : ObservableObject
|
||||
}
|
||||
_roundsRepo?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
|
||||
RoundElements.Clear();
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
|
||||
public void RoundSelected(RoundBuilderElement element)
|
||||
[RelayCommand]
|
||||
public async Task<bool> RoundSelected(RoundBuilderElement element)
|
||||
{
|
||||
bool goneOk = false;
|
||||
var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId);
|
||||
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
|
||||
if (rbGroup != null)
|
||||
{
|
||||
_objectMessage.CurrentGroup = rbGroup;
|
||||
Shell.Current.GoToAsync("//RoundRunningView");
|
||||
await Shell.Current.GoToAsync("//RoundRunningView");
|
||||
goneOk = true;
|
||||
}
|
||||
return goneOk;
|
||||
}
|
||||
|
||||
public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
|
||||
[RelayCommand]
|
||||
public async Task<bool> SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
|
||||
{
|
||||
bool goneOk = false;
|
||||
Debug.WriteLine($"Du valde raden med Runda {roundBuilder.GameRoundId} och spelare: {roundBuilder.ParticipantName}");
|
||||
goneOk = true;
|
||||
return goneOk;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user