AddTournament To list by add
This commit is contained in:
@@ -17,17 +17,22 @@ namespace Apollon.WPF
|
|||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
private readonly ModalNavigationStore _modalNavigationStore;
|
private readonly ModalNavigationStore _modalNavigationStore;
|
||||||
|
private readonly TournamentStore _tournamentStore;
|
||||||
private readonly SelectedTournamentStore _selectedTournamentStore;
|
private readonly SelectedTournamentStore _selectedTournamentStore;
|
||||||
|
|
||||||
|
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
_modalNavigationStore = new ModalNavigationStore();
|
_modalNavigationStore = new ModalNavigationStore();
|
||||||
|
_tournamentStore = new TournamentStore();
|
||||||
_selectedTournamentStore = new SelectedTournamentStore();
|
_selectedTournamentStore = new SelectedTournamentStore();
|
||||||
}
|
}
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
OverviewViewModel overviewViewModel = new OverviewViewModel(_selectedTournamentStore, _modalNavigationStore);
|
OverviewViewModel overviewViewModel = new OverviewViewModel(
|
||||||
|
_tournamentStore,
|
||||||
|
_selectedTournamentStore,
|
||||||
|
_modalNavigationStore);
|
||||||
|
|
||||||
MainWindow = new MainWindow()
|
MainWindow = new MainWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Apollon.WPF.Stores;
|
using Apollon.WPF.Models;
|
||||||
|
using Apollon.WPF.Stores;
|
||||||
|
using Apollon.WPF.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -9,16 +11,41 @@ namespace Apollon.WPF.Commands
|
|||||||
{
|
{
|
||||||
public class AddTournamentCommand : AsyncCommandBase
|
public class AddTournamentCommand : AsyncCommandBase
|
||||||
{
|
{
|
||||||
|
private readonly TournamentStore _tournamentStore;
|
||||||
private readonly ModalNavigationStore _modalNavigationStore;
|
private readonly ModalNavigationStore _modalNavigationStore;
|
||||||
|
private AddTournamentViewModel _addTournamentViewModel;
|
||||||
|
|
||||||
|
|
||||||
public AddTournamentCommand(ModalNavigationStore modalNavigationStore)
|
public AddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||||
{
|
{
|
||||||
|
_tournamentStore = tournamentStore;
|
||||||
_modalNavigationStore = modalNavigationStore;
|
_modalNavigationStore = modalNavigationStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||||
|
{
|
||||||
|
_addTournamentViewModel = addTournamentViewModel;
|
||||||
|
_tournamentStore = tournamentStore;
|
||||||
|
_modalNavigationStore = modalNavigationStore;
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task ExecuteAsync(object parameter)
|
public override async Task ExecuteAsync(object parameter)
|
||||||
{
|
{
|
||||||
|
AddEditDetailsViewModel formViewModel = _addTournamentViewModel.AddEditDetailsViewModel;
|
||||||
|
Tournament tournament = new Tournament(formViewModel.Organisation,formViewModel.Tournamentname, formViewModel.Category, formViewModel.Startdate, formViewModel.Enddate,
|
||||||
|
formViewModel.Location, formViewModel.Rounds);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _tournamentStore.Add(tournament);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
// Add Tournament to Database
|
// Add Tournament to Database
|
||||||
|
|
||||||
|
|
||||||
_modalNavigationStore.Close();
|
_modalNavigationStore.Close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,18 @@ namespace Apollon.WPF.Commands
|
|||||||
{
|
{
|
||||||
public class OpenAddTournamentCommand : CommandBase
|
public class OpenAddTournamentCommand : CommandBase
|
||||||
{
|
{
|
||||||
|
private readonly TournamentStore _tournamentStore;
|
||||||
private readonly ModalNavigationStore _modalNavigationStore;
|
private readonly ModalNavigationStore _modalNavigationStore;
|
||||||
|
|
||||||
public OpenAddTournamentCommand(ModalNavigationStore modalNavigationStore)
|
public OpenAddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||||
{
|
{
|
||||||
|
_tournamentStore = tournamentStore;
|
||||||
_modalNavigationStore = modalNavigationStore;
|
_modalNavigationStore = modalNavigationStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Execute(object parameter)
|
public override void Execute(object parameter)
|
||||||
{
|
{
|
||||||
AddTournamentViewModel addTournamentViewModel = new AddTournamentViewModel(_modalNavigationStore);
|
AddTournamentViewModel addTournamentViewModel = new AddTournamentViewModel(_tournamentStore, _modalNavigationStore);
|
||||||
_modalNavigationStore.CurrentViewModel = addTournamentViewModel;
|
_modalNavigationStore.CurrentViewModel = addTournamentViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
Apollon.WPF/Stores/TournamentStore.cs
Normal file
19
Apollon.WPF/Stores/TournamentStore.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Apollon.WPF.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Apollon.WPF.Stores
|
||||||
|
{
|
||||||
|
public class TournamentStore
|
||||||
|
{
|
||||||
|
public event Action<Tournament> TournamentAdded;
|
||||||
|
|
||||||
|
public async Task Add(Tournament tournament)
|
||||||
|
{
|
||||||
|
TournamentAdded?.Invoke(tournament);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,9 +13,9 @@ namespace Apollon.WPF.ViewModels
|
|||||||
{
|
{
|
||||||
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
|
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
|
||||||
|
|
||||||
public AddTournamentViewModel(ModalNavigationStore modalNavigationStore)
|
public AddTournamentViewModel(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||||
{
|
{
|
||||||
ICommand submitCommand = new AddTournamentCommand(modalNavigationStore);
|
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore);
|
||||||
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
|
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
|
||||||
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand);
|
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ namespace Apollon.WPF.ViewModels
|
|||||||
{
|
{
|
||||||
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
|
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
|
||||||
private readonly SelectedTournamentStore _selectedTournamentStore;
|
private readonly SelectedTournamentStore _selectedTournamentStore;
|
||||||
|
private readonly ModalNavigationStore _modalNavigationStore;
|
||||||
|
private readonly TournamentStore _tournamentStore;
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
|
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
|
||||||
|
|
||||||
@@ -35,20 +38,36 @@ namespace Apollon.WPF.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public OverviewListingViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
public OverviewListingViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentStore tournamentStore)
|
||||||
{
|
{
|
||||||
|
_tournamentStore = tournamentStore;
|
||||||
_selectedTournamentStore = selectedTournamentStore;
|
_selectedTournamentStore = selectedTournamentStore;
|
||||||
|
_modalNavigationStore = modalNavigationStore;
|
||||||
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
||||||
|
|
||||||
AddTournament(new Tournament("DSB", "Deutschemeisterschaft1", "Halle", "01.01.2021", "05.01.2021", "Wiesbaden",3),modalNavigationStore);
|
_tournamentStore.TournamentAdded += _tournamentStore_TournamentAdded;
|
||||||
AddTournament(new Tournament("DSB", "Deutschemeisterschaft2", "im Freien", "01.01.2021", "05.01.2021", "Berlin",5),modalNavigationStore);
|
|
||||||
AddTournament(new Tournament("DSB", "Deutschemeisterschaft3", "Halle", "01.01.2021", "05.01.2021", "Bruchsal", 6),modalNavigationStore);
|
//AddTournament(new Tournament("DSB", "Deutschemeisterschaft1", "Halle", "01.01.2021", "05.01.2021", "Wiesbaden",3),modalNavigationStore);
|
||||||
|
//AddTournament(new Tournament("DSB", "Deutschemeisterschaft2", "im Freien", "01.01.2021", "05.01.2021", "Berlin",5),modalNavigationStore);
|
||||||
|
//AddTournament(new Tournament("DSB", "Deutschemeisterschaft3", "Halle", "01.01.2021", "05.01.2021", "Bruchsal", 6),modalNavigationStore);
|
||||||
|
|
||||||
}
|
}
|
||||||
private void AddTournament(Tournament tournament, ModalNavigationStore modalNavigationStore)
|
|
||||||
|
protected override void Dispose()
|
||||||
{
|
{
|
||||||
ICommand editTournamentCommand = new OpenAddTournamentCommand(modalNavigationStore);
|
_tournamentStore.TournamentAdded -= _tournamentStore_TournamentAdded;
|
||||||
|
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _tournamentStore_TournamentAdded(Tournament tournament)
|
||||||
|
{
|
||||||
|
AddTournament(tournament);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddTournament(Tournament tournament)
|
||||||
|
{
|
||||||
|
//ICommand editTournamentCommand = new OpenEditTournamentCommand(_modalNavigationStore);
|
||||||
_overviewListingItemViewModels.Add(new OverviewListingItemViewModel(tournament
|
_overviewListingItemViewModels.Add(new OverviewListingItemViewModel(tournament
|
||||||
//,editTournamentCommand
|
//,editTournamentCommand
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ namespace Apollon.WPF.ViewModels
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public OverviewViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
public OverviewViewModel(TournamentStore tournamentStore, SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
||||||
{
|
{
|
||||||
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore);
|
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
||||||
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
||||||
|
|
||||||
AddTournamentCommand = new OpenAddTournamentCommand(modalNavigationStore);
|
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
||||||
//EditTournamentCommand = new OpenEditTournamentCommand(modalNavigationStore);
|
//EditTournamentCommand = new OpenEditTournamentCommand(modalNavigationStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user