Edit Function are available
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Apollon.WPF.ViewModels
|
||||
{
|
||||
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
|
||||
|
||||
public AddTournamentViewModel(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
public AddTournamentViewModel(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore);
|
||||
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
|
||||
|
||||
@@ -12,13 +12,26 @@ namespace Apollon.WPF.ViewModels
|
||||
{
|
||||
public class EditTournamentViewModel : ViewModelBase
|
||||
{
|
||||
public Guid TournamentId { get;}
|
||||
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
|
||||
|
||||
public EditTournamentViewModel(ModalNavigationStore modalNavigationStore)
|
||||
public EditTournamentViewModel(ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore, Tournament tournament)
|
||||
{
|
||||
ICommand submitCommand = new EditTournamentCommand(modalNavigationStore);
|
||||
TournamentId = tournament.Id;
|
||||
|
||||
ICommand submitCommand = new EditTournamentCommand(this, tournamentStore, modalNavigationStore);
|
||||
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
|
||||
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand);
|
||||
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand)
|
||||
|
||||
{
|
||||
Organisation = tournament.Organisation,
|
||||
TournamentName = tournament.TournamentName,
|
||||
Competition = tournament.Competition,
|
||||
StartDate = tournament.StartDate,
|
||||
EndDate = tournament.EndDate,
|
||||
Location = tournament.Location,
|
||||
Rounds = tournament.Rounds,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Apollon.WPF.ViewModels
|
||||
{
|
||||
public class OverviewDetailsViewModel : ViewModelBase
|
||||
{
|
||||
private readonly SelectedTournamentStore _selectedTournamentStore;
|
||||
private readonly SelectedTournamentsStore _selectedTournamentStore;
|
||||
|
||||
private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Apollon.WPF.ViewModels
|
||||
public string Location => SelectedTournament?.Location ?? "kein Ort";
|
||||
public int Rounds => SelectedTournament?.Rounds ?? 0;
|
||||
|
||||
public OverviewDetailsViewModel(SelectedTournamentStore selectedTournamentStore)
|
||||
public OverviewDetailsViewModel(SelectedTournamentsStore selectedTournamentStore)
|
||||
{
|
||||
_selectedTournamentStore = selectedTournamentStore;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.WPF.Commands;
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,16 +11,28 @@ using System.Windows.Input;
|
||||
namespace Apollon.WPF.ViewModels
|
||||
{
|
||||
public class OverviewListingItemViewModel : ViewModelBase
|
||||
{
|
||||
public Tournament Tournament { get;}
|
||||
{
|
||||
public Tournament Tournament { get; private set; }
|
||||
|
||||
public string TournamentName => Tournament.TournamentName;
|
||||
public string Location => Tournament.Location;
|
||||
|
||||
public ICommand EditCommand { get; }
|
||||
public ICommand DeleteCommand { get; }
|
||||
|
||||
public OverviewListingItemViewModel(Tournament tournament)
|
||||
|
||||
public OverviewListingItemViewModel(Tournament tournament, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
Tournament = tournament;
|
||||
|
||||
EditCommand = new OpenEditTournamentCommand(this, tournamentStore, modalNavigationStore);
|
||||
}
|
||||
|
||||
public void Update(Tournament tournament)
|
||||
{
|
||||
Tournament = tournament;
|
||||
|
||||
OnPropertyChanged(nameof(TournamentName));
|
||||
OnPropertyChanged(nameof(Location));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace Apollon.WPF.ViewModels
|
||||
public class OverviewListingViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
|
||||
private readonly SelectedTournamentStore _selectedTournamentStore;
|
||||
private readonly SelectedTournamentsStore _selectedTournamentStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
private readonly TournamentStore _tournamentStore;
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
|
||||
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
|
||||
@@ -38,19 +38,21 @@ namespace Apollon.WPF.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public OverviewListingViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentStore tournamentStore)
|
||||
public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
|
||||
{
|
||||
_tournamentStore = tournamentStore;
|
||||
_selectedTournamentStore = selectedTournamentStore;
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
||||
|
||||
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
|
||||
}
|
||||
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
|
||||
_tournamentStore.TournamentUpdated += TournamentStore_TournamentUpdated;
|
||||
}
|
||||
|
||||
protected override void Dispose()
|
||||
{
|
||||
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
|
||||
_tournamentStore.TournamentUpdated -= TournamentStore_TournamentUpdated;
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
@@ -59,10 +61,21 @@ namespace Apollon.WPF.ViewModels
|
||||
AddTournament(tournament);
|
||||
}
|
||||
|
||||
private void TournamentStore_TournamentUpdated(Tournament tournament)
|
||||
{
|
||||
OverviewListingItemViewModel overviewViewModel =
|
||||
_overviewListingItemViewModels.FirstOrDefault(y => y.Tournament.Id == tournament.Id);
|
||||
|
||||
if(overviewViewModel != null)
|
||||
{
|
||||
overviewViewModel.Update(tournament);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddTournament(Tournament tournament)
|
||||
{
|
||||
// TO DO EditTournamentCommand
|
||||
_overviewListingItemViewModels.Add(new OverviewListingItemViewModel(tournament));
|
||||
OverviewListingItemViewModel itemViewModel = new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
|
||||
_overviewListingItemViewModels.Add(itemViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,20 +15,14 @@ namespace Apollon.WPF.ViewModels
|
||||
public OverviewListingViewModel OverviewListingViewModel { get; }
|
||||
public OverviewDetailsViewModel OverviewDetailsViewModel{ get; }
|
||||
|
||||
public ICommand AddTournamentCommand { get; }
|
||||
public ICommand EditTournamentCommand { get;}
|
||||
public ICommand AddTournamentCommand { get; }
|
||||
|
||||
|
||||
|
||||
public OverviewViewModel(TournamentStore tournamentStore, SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
||||
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
||||
|
||||
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
||||
EditTournamentCommand = new OpenEditTournamentCommand(modalNavigationStore);
|
||||
|
||||
|
||||
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user