Files
GreadyPoang/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs

101 lines
2.8 KiB
C#

using Common.Library;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class RoundStartingViewModelCommands : RoundStartingViewModel
{
public RoundStartingViewModelCommands() : base()
{
}
public RoundStartingViewModelCommands(
IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base(roundsRepo, pointsRepo, sharingService, combined)
{
}
#region Private Variables
private bool _IsSaveCommandEnabled = true;
#endregion
#region Public Properties
public bool IsSaveCommandEnabled
{
get { return _IsSaveCommandEnabled; }
set
{
_IsSaveCommandEnabled = value;
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
}
}
#endregion
#region Commands
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
public ICommand RensaCommand { get; private set; }
public ICommand ElementTappedCommand { get; private set; }
public ICommand ParticipantTappedCommand { get; private set; }
#endregion
#region Init Method
public override void Init()
{
base.Init();
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
RensaCommand = new Command(async () => RensaAsync());
ParticipantTappedCommand = new Command<RoundBuilderElement>(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant));
ElementTappedCommand = new Command<RoundBuilderElement>((selectedElement) => RoundSelected(selectedElement));
}
private async Task RensaAsync()
{
base.Rensa();
await Shell.Current.GoToAsync("..");
}
#endregion
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.RoundStartingView)}?id={id}");
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
public async Task<bool> RoundSelected(RoundBuilderElement element)
{
bool goneOk = false;
base.RoundSelected(element);
goneOk = true;
return goneOk;
}
public async Task<bool> SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{
bool goneOk = false;
base.SelectNewlyAddedParticipant(roundBuilder);
goneOk = true;
return goneOk;
}
}