diff --git a/Apollon.WPF/App.xaml.cs b/Apollon.WPF/App.xaml.cs index 9cf1f76..b4c42d0 100644 --- a/Apollon.WPF/App.xaml.cs +++ b/Apollon.WPF/App.xaml.cs @@ -17,17 +17,22 @@ namespace Apollon.WPF public partial class App : Application { private readonly ModalNavigationStore _modalNavigationStore; + private readonly TournamentStore _tournamentStore; private readonly SelectedTournamentStore _selectedTournamentStore; public App() { _modalNavigationStore = new ModalNavigationStore(); + _tournamentStore = new TournamentStore(); _selectedTournamentStore = new SelectedTournamentStore(); } protected override void OnStartup(StartupEventArgs e) { - OverviewViewModel overviewViewModel = new OverviewViewModel(_selectedTournamentStore, _modalNavigationStore); + OverviewViewModel overviewViewModel = new OverviewViewModel( + _tournamentStore, + _selectedTournamentStore, + _modalNavigationStore); MainWindow = new MainWindow() { diff --git a/Apollon.WPF/Commands/AddTournamentCommand.cs b/Apollon.WPF/Commands/AddTournamentCommand.cs index 391eba0..fbd653b 100644 --- a/Apollon.WPF/Commands/AddTournamentCommand.cs +++ b/Apollon.WPF/Commands/AddTournamentCommand.cs @@ -1,4 +1,6 @@ -using Apollon.WPF.Stores; +using Apollon.WPF.Models; +using Apollon.WPF.Stores; +using Apollon.WPF.ViewModels; using System; using System.Collections.Generic; using System.Linq; @@ -9,16 +11,41 @@ namespace Apollon.WPF.Commands { public class AddTournamentCommand : AsyncCommandBase { + private readonly TournamentStore _tournamentStore; private readonly ModalNavigationStore _modalNavigationStore; + private AddTournamentViewModel _addTournamentViewModel; + - public AddTournamentCommand(ModalNavigationStore modalNavigationStore) + 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.Category, formViewModel.Startdate, formViewModel.Enddate, + formViewModel.Location, formViewModel.Rounds); + + try + { + await _tournamentStore.Add(tournament); + } + catch (Exception) + { + + throw; + } // Add Tournament to Database + _modalNavigationStore.Close(); } diff --git a/Apollon.WPF/Commands/OpenAddTournamentCommand.cs b/Apollon.WPF/Commands/OpenAddTournamentCommand.cs index 6169e3d..b7b4f55 100644 --- a/Apollon.WPF/Commands/OpenAddTournamentCommand.cs +++ b/Apollon.WPF/Commands/OpenAddTournamentCommand.cs @@ -10,16 +10,18 @@ namespace Apollon.WPF.Commands { public class OpenAddTournamentCommand : CommandBase { + private readonly TournamentStore _tournamentStore; private readonly ModalNavigationStore _modalNavigationStore; - public OpenAddTournamentCommand(ModalNavigationStore modalNavigationStore) + public OpenAddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore) { + _tournamentStore = tournamentStore; _modalNavigationStore = modalNavigationStore; } public override void Execute(object parameter) { - AddTournamentViewModel addTournamentViewModel = new AddTournamentViewModel(_modalNavigationStore); + AddTournamentViewModel addTournamentViewModel = new AddTournamentViewModel(_tournamentStore, _modalNavigationStore); _modalNavigationStore.CurrentViewModel = addTournamentViewModel; } } diff --git a/Apollon.WPF/Stores/TournamentStore.cs b/Apollon.WPF/Stores/TournamentStore.cs new file mode 100644 index 0000000..7e39a8b --- /dev/null +++ b/Apollon.WPF/Stores/TournamentStore.cs @@ -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 TournamentAdded; + + public async Task Add(Tournament tournament) + { + TournamentAdded?.Invoke(tournament); + } + } +} diff --git a/Apollon.WPF/ViewModels/AddTournametViewModel.cs b/Apollon.WPF/ViewModels/AddTournametViewModel.cs index bcbffd9..8b1fd2b 100644 --- a/Apollon.WPF/ViewModels/AddTournametViewModel.cs +++ b/Apollon.WPF/ViewModels/AddTournametViewModel.cs @@ -13,9 +13,9 @@ namespace Apollon.WPF.ViewModels { 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); AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand); } diff --git a/Apollon.WPF/ViewModels/OverviewListingViewModel.cs b/Apollon.WPF/ViewModels/OverviewListingViewModel.cs index b5c4f51..90b74f3 100644 --- a/Apollon.WPF/ViewModels/OverviewListingViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewListingViewModel.cs @@ -15,6 +15,9 @@ namespace Apollon.WPF.ViewModels { private readonly ObservableCollection _overviewListingItemViewModels; private readonly SelectedTournamentStore _selectedTournamentStore; + private readonly ModalNavigationStore _modalNavigationStore; + private readonly TournamentStore _tournamentStore; + public IEnumerable 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; + _modalNavigationStore = modalNavigationStore; _overviewListingItemViewModels = new ObservableCollection(); - 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); + _tournamentStore.TournamentAdded += _tournamentStore_TournamentAdded; + + //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 //,editTournamentCommand )); diff --git a/Apollon.WPF/ViewModels/OverviewViewModel.cs b/Apollon.WPF/ViewModels/OverviewViewModel.cs index 853ce61..cd2b8f0 100644 --- a/Apollon.WPF/ViewModels/OverviewViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewViewModel.cs @@ -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); - AddTournamentCommand = new OpenAddTournamentCommand(modalNavigationStore); + AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore); //EditTournamentCommand = new OpenEditTournamentCommand(modalNavigationStore); } }