From 8b2b77bb569c54453591fce8e43607c137af4993 Mon Sep 17 00:00:00 2001 From: Natlinux81 <97396587+Natlinux81@users.noreply.github.com> Date: Sat, 10 Sep 2022 16:25:19 +0200 Subject: [PATCH] Navigate to NavBar with data --- Apollon.WPF/Commands/AddTournamentCommand.cs | 4 ++-- Apollon.WPF/Commands/EditTournamentCommand.cs | 1 + Apollon.WPF/ViewModels/NavBarViewModel.cs | 19 ++++++++++++++++- .../ViewModels/OverviewDetailsViewModel.cs | 10 +++++++-- Apollon.WPF/ViewModels/OverviewViewModel.cs | 7 ++----- .../Views/Components/OverviewDetails.xaml | 21 ++++++++++++++++++- .../Views/Components/TournamentDetails.xaml | 14 ++++++------- Apollon.WPF/Views/OverviewView.xaml | 8 ------- 8 files changed, 58 insertions(+), 26 deletions(-) diff --git a/Apollon.WPF/Commands/AddTournamentCommand.cs b/Apollon.WPF/Commands/AddTournamentCommand.cs index d8025a2..26e6b87 100644 --- a/Apollon.WPF/Commands/AddTournamentCommand.cs +++ b/Apollon.WPF/Commands/AddTournamentCommand.cs @@ -50,8 +50,8 @@ namespace Apollon.WPF.Commands await _tournamentStore.Add(tournament); _modalNavigationStore.Close(); - //_navigationStore.CurrentViewModel = new NavBarViewModel(_navigationStore, _selectedTournamentsStore, _modalNavigationStore,_tournamentStore); - + _navigationStore.CurrentViewModel = new NavBarViewModel(_navigationStore, _selectedTournamentsStore, _modalNavigationStore, _tournamentStore); + } catch (Exception) { diff --git a/Apollon.WPF/Commands/EditTournamentCommand.cs b/Apollon.WPF/Commands/EditTournamentCommand.cs index bd4a237..7abd6ce 100644 --- a/Apollon.WPF/Commands/EditTournamentCommand.cs +++ b/Apollon.WPF/Commands/EditTournamentCommand.cs @@ -45,6 +45,7 @@ namespace Apollon.WPF.Commands await _tournamentStore.Update(tournament); _modalNavigationStore.Close(); + } catch (Exception) { diff --git a/Apollon.WPF/ViewModels/NavBarViewModel.cs b/Apollon.WPF/ViewModels/NavBarViewModel.cs index 46499fa..fcd9335 100644 --- a/Apollon.WPF/ViewModels/NavBarViewModel.cs +++ b/Apollon.WPF/ViewModels/NavBarViewModel.cs @@ -1,4 +1,5 @@ -using Apollon.WPF.Commands; +using Apollon.Domain.Models; +using Apollon.WPF.Commands; using Apollon.WPF.Stores; using System; using System.Collections.Generic; @@ -12,12 +13,28 @@ namespace Apollon.WPF.ViewModels public class NavBarViewModel : ViewModelBase { + + private readonly SelectedTournamentsStore _selectedTournamentsStore; + private Tournament SelectedTournament => _selectedTournamentsStore.SelectedTournament; + + public bool HasSelectedTournament => SelectedTournament != null; + public string Organisation => SelectedTournament?.Organisation ?? "keine Organisation"; + public string TournamentName => SelectedTournament?.TournamentName ?? "kein Name"; + public string Competition => SelectedTournament?.Competition ?? "keine Kategorie"; + public string CompetitionImage => SelectedTournament?.CompetitionImage ?? "D:\\Projekte\\Apollon\\Apollon\\Apollon.WPF\\Images\\Archery.png"; + public string StartDate => SelectedTournament?.StartDate.ToString("d") ?? "kein Datum"; + public string EndDate => SelectedTournament?.EndDate.ToString("d") ?? "kein Datum"; + public string Location => SelectedTournament?.Location ?? "kein Ort"; + public int Rounds => SelectedTournament?.Rounds ?? 0; + + public AddEditDetailsViewModel AddEditDetailsViewModel { get; } public ICommand NavigateOverviewCommand { get; } public NavBarViewModel(NavigationStore navigationStore, SelectedTournamentsStore selectedTournamentsStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentsStore) { NavigateOverviewCommand = new NavigateCommand(navigationStore, () => new OverviewViewModel(tournamentsStore, selectedTournamentsStore, modalNavigationStore,navigationStore)); + _selectedTournamentsStore = selectedTournamentsStore; } } } diff --git a/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs b/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs index 2b942a0..6b0bc82 100644 --- a/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs @@ -1,10 +1,12 @@ using Apollon.Domain.Models; +using Apollon.WPF.Commands; using Apollon.WPF.Stores; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; namespace Apollon.WPF.ViewModels { @@ -23,11 +25,15 @@ namespace Apollon.WPF.ViewModels public string Location => SelectedTournament?.Location ?? "kein Ort"; public int Rounds => SelectedTournament?.Rounds ?? 0; - public OverviewDetailsViewModel(SelectedTournamentsStore selectedTournamentStore) + public ICommand NavigateNavBarCommand { get; } + + public OverviewDetailsViewModel(SelectedTournamentsStore selectedTournamentStore, NavigationStore navigationStore, ModalNavigationStore modalNavigationStore,TournamentsStore tournamentsStore) { _selectedTournamentStore = selectedTournamentStore; - _selectedTournamentStore.SelectedTournamentChanged += SelectedTournamentStore_SelectedTournamentChanged; + _selectedTournamentStore.SelectedTournamentChanged += SelectedTournamentStore_SelectedTournamentChanged; + + NavigateNavBarCommand = new NavigateCommand(navigationStore, () => new NavBarViewModel(navigationStore, selectedTournamentStore, modalNavigationStore, tournamentsStore)); } protected override void Dispose() diff --git a/Apollon.WPF/ViewModels/OverviewViewModel.cs b/Apollon.WPF/ViewModels/OverviewViewModel.cs index f573f34..ab1d945 100644 --- a/Apollon.WPF/ViewModels/OverviewViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewViewModel.cs @@ -47,19 +47,16 @@ namespace Apollon.WPF.ViewModels public bool HasErrorMessage => !string.IsNullOrEmpty(ErrorMessage); public ICommand AddTournamentCommand { get; } - public ICommand LoadTournamentsCommand { get; } - public ICommand NavigateNavBarCommand { get; } + public ICommand LoadTournamentsCommand { get; } public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, NavigationStore navigationStore) { OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore); - OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore); + OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore ,navigationStore, modalNavigationStore,tournamentStore); LoadTournamentsCommand = new LoadTournamentsCommand(this, tournamentStore); AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore, navigationStore, selectedTournamentStore); - NavigateNavBarCommand = new NavigateCommand(navigationStore, () => new NavBarViewModel(navigationStore,selectedTournamentStore,modalNavigationStore,tournamentStore)); - } public static OverviewViewModel LoadViewModel(SelectedTournamentsStore selectedTournamentStore, diff --git a/Apollon.WPF/Views/Components/OverviewDetails.xaml b/Apollon.WPF/Views/Components/OverviewDetails.xaml index 59ede64..dd4e54f 100644 --- a/Apollon.WPF/Views/Components/OverviewDetails.xaml +++ b/Apollon.WPF/Views/Components/OverviewDetails.xaml @@ -218,7 +218,26 @@ - + + diff --git a/Apollon.WPF/Views/Components/TournamentDetails.xaml b/Apollon.WPF/Views/Components/TournamentDetails.xaml index bd25baf..32f835c 100644 --- a/Apollon.WPF/Views/Components/TournamentDetails.xaml +++ b/Apollon.WPF/Views/Components/TournamentDetails.xaml @@ -18,14 +18,14 @@ VerticalAlignment="Center"/> - - - - - - diff --git a/Apollon.WPF/Views/OverviewView.xaml b/Apollon.WPF/Views/OverviewView.xaml index 5483148..e091de5 100644 --- a/Apollon.WPF/Views/OverviewView.xaml +++ b/Apollon.WPF/Views/OverviewView.xaml @@ -156,14 +156,6 @@ -