Files
Apollon/Apollon.WPF/Commands/AddTournamentCommand.cs
2022-08-18 04:13:30 +02:00

58 lines
1.8 KiB
C#

using Apollon.WPF.Models;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.Commands
{
public class AddTournamentCommand : AsyncCommandBase
{
private readonly TournamentStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
private AddTournamentViewModel _addTournamentViewModel;
public AddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
}
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_addTournamentViewModel = addTournamentViewModel;
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
}
public override async Task ExecuteAsync(object parameter)
{
AddEditDetailsViewModel formViewModel = _addTournamentViewModel.AddEditDetailsViewModel;
Tournament tournament = new Tournament(
formViewModel.Organisation,
formViewModel.TournamentName,
formViewModel.Competition,
formViewModel.StartDate,
formViewModel.EndDate,
formViewModel.Location,
formViewModel.Rounds);
try
{
await _tournamentStore.Add(tournament);
_modalNavigationStore.Close();
}
catch (Exception)
{
throw;
}
}
}
}