Files
Apollon/Apollon.WPF/ViewModels/OverviewListingViewModel.cs
2022-08-18 04:13:30 +02:00

69 lines
2.4 KiB
C#

using Apollon.WPF.Commands;
using Apollon.WPF.Models;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Apollon.WPF.ViewModels
{
public class OverviewListingViewModel : ViewModelBase
{
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
private readonly SelectedTournamentStore _selectedTournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
private readonly TournamentStore _tournamentStore;
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
private OverviewListingItemViewModel _selectedOverviewListingItemViewModel;
public OverviewListingItemViewModel SelectedOverviewListingItemViewModel
{
get
{
return _selectedOverviewListingItemViewModel;
}
set
{
_selectedOverviewListingItemViewModel = value;
OnPropertyChanged(nameof(SelectedOverviewListingItemViewModel));
_selectedTournamentStore.SelectedTournament = _selectedOverviewListingItemViewModel.Tournament;
}
}
public OverviewListingViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentStore tournamentStore)
{
_tournamentStore = tournamentStore;
_selectedTournamentStore = selectedTournamentStore;
_modalNavigationStore = modalNavigationStore;
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
}
protected override void Dispose()
{
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
base.Dispose();
}
private void TournamentStore_TournamentAdded(Tournament tournament)
{
AddTournament(tournament);
}
private void AddTournament(Tournament tournament)
{
// TO DO EditTournamentCommand
_overviewListingItemViewModels.Add(new OverviewListingItemViewModel(tournament));
}
}
}