impliment NavigateService

This commit is contained in:
Natlinux
2022-11-26 20:40:45 +01:00
parent 873d130aaa
commit 439850b5b7
7 changed files with 56 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
using Apollon.Domain.Models;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;
@@ -12,19 +13,23 @@ namespace Apollon.WPF.Commands
public class AddTournamentCommand : AsyncCommandBase
{
private readonly TournamentsStore _tournamentStore;
private readonly NavigationStore _navigationStore;
private readonly NavigationService<PreparationViewModel> _navigationService;
private readonly ModalNavigationStore _modalNavigationStore;
private readonly SelectedTournamentsStore _selectedTournamentsStore;
private AddTournamentViewModel _addTournamentViewModel;
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore, NavigationStore navigationStore, SelectedTournamentsStore selectedTournamentsStore)
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, NavigationService<PreparationViewModel> navigationService)
{
}
public AddTournamentCommand(TournamentsStore tournamentStore, NavigationService<PreparationViewModel> navigationService, ModalNavigationStore modalNavigationStore,
SelectedTournamentsStore selectedTournamentsStore, AddTournamentViewModel addTournamentViewModel)
{
_addTournamentViewModel = addTournamentViewModel;
_tournamentStore = tournamentStore;
_navigationService = navigationService;
_modalNavigationStore = modalNavigationStore;
_navigationStore = navigationStore;
_selectedTournamentsStore = selectedTournamentsStore;
_addTournamentViewModel = addTournamentViewModel;
}
public override async Task ExecuteAsync(object parameter)
@@ -52,7 +57,7 @@ namespace Apollon.WPF.Commands
await _tournamentStore.Add(tournament);
_modalNavigationStore.Close();
_navigationStore.CurrentViewModel = new PreparationViewModel(_selectedTournamentsStore, _navigationStore, _modalNavigationStore, _tournamentStore);
_navigationService.Navigate();
}
catch (Exception)

View File

@@ -1,4 +1,5 @@
using Apollon.WPF.Stores;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;
using System.Collections.Generic;
@@ -11,18 +12,16 @@ namespace Apollon.WPF.Commands
public class NavigateCommand<TViewModel> : CommandBase
where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;
private readonly NavigationService<TViewModel> _navigationService;
public NavigateCommand(NavigationStore navigationStore, Func<TViewModel> createViewModel)
public NavigateCommand(NavigationService<TViewModel> navigationService)
{
_navigationStore = navigationStore;
_createViewModel = createViewModel;
_navigationService = navigationService;
}
public override void Execute(object parameter)
{
_navigationStore.CurrentViewModel = _createViewModel();
_navigationService.Navigate();
}
}
}

View File

@@ -0,0 +1,28 @@
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.Services
{
public class NavigationService<TViewModel>
where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;
public NavigationService(NavigationStore navigationStore, Func<TViewModel> createViewModel)
{
_navigationStore = navigationStore;
_createViewModel = createViewModel;
}
public void Navigate()
{
_navigationStore.CurrentViewModel = _createViewModel();
}
}
}

View File

@@ -1,4 +1,5 @@
using Apollon.WPF.Commands;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
@@ -15,7 +16,7 @@ namespace Apollon.WPF.ViewModels
public AddTournamentViewModel(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore, NavigationStore navigationStore,SelectedTournamentsStore selectedTournamentsStore)
{
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore,navigationStore, selectedTournamentsStore);
ICommand submitCommand = new AddTournamentCommand(this, new NavigationService<PreparationViewModel>(navigationStore, () => new PreparationViewModel( selectedTournamentsStore, navigationStore, modalNavigationStore, tournamentStore)));
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand);
}

View File

@@ -1,5 +1,6 @@
using Apollon.Domain.Models;
using Apollon.WPF.Commands;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
@@ -35,7 +36,8 @@ namespace Apollon.WPF.ViewModels
_selectedTournamentStore.SelectedTournamentChanged += SelectedTournamentStore_SelectedTournamentChanged;
NavigateTournamentDetailsCommand = new NavigateCommand<PreparationViewModel>(navigationStore, () => new PreparationViewModel(_selectedTournamentStore,navigationStore, modalNavigationStore, tournamentsStore));
NavigateTournamentDetailsCommand = new NavigateCommand<PreparationViewModel>(new NavigationService<PreparationViewModel>(navigationStore,() => new PreparationViewModel(
selectedTournamentStore,navigationStore,modalNavigationStore, tournamentsStore)));
}
protected override void Dispose()

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Apollon.WPF.Services;
namespace Apollon.WPF.ViewModels
{
@@ -58,7 +59,7 @@ namespace Apollon.WPF.ViewModels
LoadTournamentsCommand = new LoadTournamentsCommand(this, tournamentStore);
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore, navigationStore, selectedTournamentStore);
NavigateNameListCommand = new NavigateCommand<NameListViewModel>(navigationStore, () => new NameListViewModel());
NavigateNameListCommand = new NavigateCommand<NameListViewModel>(new NavigationService<NameListViewModel>(navigationStore, () => new NameListViewModel()));
}

View File

@@ -1,5 +1,6 @@
using Apollon.Domain.Models;
using Apollon.WPF.Commands;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
@@ -21,7 +22,8 @@ namespace Apollon.WPF.ViewModels
{
TournamentDetailsViewModel = new TournamentDetailsViewModel(selectedTournamentStore);
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(navigationStore, () => OverviewViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentsStore, navigationStore));
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(new NavigationService<OverviewViewModel>(navigationStore, () => OverviewViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentsStore, navigationStore)));
}
}