deleted still shows on the details panel
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Apollon.EntityFramework
|
||||
|
||||
public TournamentsDbContext CreateDbContext(string[] args = null)
|
||||
{
|
||||
return new TournamentsDbContext(new DbContextOptionsBuilder().UseSqlServer("Data Source=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true").Options);
|
||||
return new TournamentsDbContext(new DbContextOptionsBuilder().UseSqlServer("Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true").Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,8 @@ namespace Apollon.WPF.Commands
|
||||
{
|
||||
await ExecuteAsync(parameter);
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
public abstract Task ExecuteAsync(object parameter);
|
||||
}
|
||||
}
|
||||
|
||||
37
Apollon.WPF/Commands/DeleteTournamentCommand.cs
Normal file
37
Apollon.WPF/Commands/DeleteTournamentCommand.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Apollon.Domain.Models;
|
||||
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.Commands
|
||||
{
|
||||
public class DeleteTournamentCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly OverviewListingItemViewModel _overviewListingItemViewModel;
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
public DeleteTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentStore)
|
||||
{
|
||||
_overviewListingItemViewModel = overviewListingItemViewModel;
|
||||
_tournamentStore = tournamentStore;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(object parameter)
|
||||
{
|
||||
Tournament tournament = _overviewListingItemViewModel.Tournament;
|
||||
|
||||
try
|
||||
{
|
||||
await _tournamentStore.Delete(tournament.Id);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Apollon.WPF/Commands/LoadTournamentsCommand.cs
Normal file
31
Apollon.WPF/Commands/LoadTournamentsCommand.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.WPF.Commands
|
||||
{
|
||||
public class LoadTournamentsCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
public LoadTournamentsCommand(TournamentsStore tournamentStore)
|
||||
{
|
||||
_tournamentStore = tournamentStore;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(object parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _tournamentStore.Load();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,9 @@ namespace Apollon.WPF.Commands
|
||||
private readonly OverviewListingItemViewModel _overviewListingItemViewModel;
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
public OpenEditTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
public OpenEditTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel,
|
||||
TournamentsStore tournamentStore,
|
||||
ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
_overviewListingItemViewModel = overviewListingItemViewModel;
|
||||
_tournamentStore = tournamentStore;
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace Apollon.WPF.Stores
|
||||
{
|
||||
public class SelectedTournamentsStore
|
||||
{
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
private Tournament _selectedTournament;
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
private Tournament _selectedTournament;
|
||||
|
||||
public Tournament SelectedTournament
|
||||
{
|
||||
@@ -42,5 +42,6 @@ namespace Apollon.WPF.Stores
|
||||
SelectedTournament = tournament;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,14 @@ namespace Apollon.WPF.Stores
|
||||
private readonly ICreateTournamentCommand _createTournamentCommand;
|
||||
private readonly IUpdateTournamentCommand _updateTournamentCommand;
|
||||
private readonly IDeleteTournamentCommand _deleteTournamentCommand;
|
||||
private readonly List<Tournament> _tournaments;
|
||||
|
||||
public IEnumerable<Tournament> Tournaments => _tournaments;
|
||||
|
||||
public event Action TournamentLoaded;
|
||||
public event Action<Tournament> TournamentAdded;
|
||||
public event Action<Tournament> TournamentUpdated;
|
||||
public event Action<Guid> TournamentDeleted;
|
||||
|
||||
public TournamentsStore(IGetAllTournamentsQuery getAllTournamentQuery,
|
||||
ICreateTournamentCommand createTournamentCommand,
|
||||
@@ -25,10 +33,19 @@ namespace Apollon.WPF.Stores
|
||||
_createTournamentCommand = createTournamentCommand;
|
||||
_updateTournamentCommand = updateTournamentCommand;
|
||||
_deleteTournamentCommand = deleteTournamentCommand;
|
||||
}
|
||||
|
||||
public event Action<Tournament> TournamentAdded;
|
||||
public event Action<Tournament> TournamentUpdated;
|
||||
_tournaments = new List<Tournament>();
|
||||
}
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
IEnumerable<Tournament> tournaments = await _getAllTournamentQuery.Execute();
|
||||
|
||||
_tournaments.Clear();
|
||||
_tournaments.AddRange(tournaments);
|
||||
|
||||
TournamentLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public async Task Add(Tournament tournament)
|
||||
{
|
||||
@@ -36,10 +53,31 @@ namespace Apollon.WPF.Stores
|
||||
TournamentAdded?.Invoke(tournament);
|
||||
}
|
||||
|
||||
public async Task Update (Tournament tournament)
|
||||
public async Task Update(Tournament tournament)
|
||||
{
|
||||
await _updateTournamentCommand.Execute(tournament);
|
||||
|
||||
int currentIndex = _tournaments.FindIndex(y => y.Id == tournament.Id);
|
||||
|
||||
if (currentIndex == -1)
|
||||
{
|
||||
_tournaments[currentIndex] = tournament;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tournaments.Add(tournament);
|
||||
}
|
||||
|
||||
TournamentUpdated?.Invoke(tournament);
|
||||
}
|
||||
|
||||
public async Task Delete(Guid id)
|
||||
{
|
||||
await _deleteTournamentCommand.Execute(id);
|
||||
|
||||
_tournaments.RemoveAll(y => y.Id == id);
|
||||
|
||||
TournamentDeleted?.Invoke(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Apollon.WPF.ViewModels
|
||||
Tournament = tournament;
|
||||
|
||||
EditCommand = new OpenEditTournamentCommand(this, tournamentStore, modalNavigationStore);
|
||||
DeleteCommand = new DeleteTournamentCommand(this, tournamentStore);
|
||||
}
|
||||
|
||||
public void Update(Tournament tournament)
|
||||
|
||||
@@ -16,12 +16,11 @@ namespace Apollon.WPF.ViewModels
|
||||
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
|
||||
private readonly SelectedTournamentsStore _selectedTournamentStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
|
||||
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
|
||||
|
||||
private OverviewListingItemViewModel _selectedOverviewListingItemViewModel;
|
||||
private OverviewListingItemViewModel _selectedOverviewListingItemViewModel;
|
||||
|
||||
public OverviewListingItemViewModel SelectedOverviewListingItemViewModel
|
||||
{
|
||||
@@ -38,6 +37,8 @@ namespace Apollon.WPF.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand LoadTournamentsCommand { get;}
|
||||
|
||||
public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
|
||||
{
|
||||
_tournamentStore = tournamentStore;
|
||||
@@ -45,17 +46,43 @@ namespace Apollon.WPF.ViewModels
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
||||
|
||||
LoadTournamentsCommand = new LoadTournamentsCommand(tournamentStore);
|
||||
|
||||
_tournamentStore.TournamentLoaded += TournamentStore_TournamentLoaded;
|
||||
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
|
||||
_tournamentStore.TournamentUpdated += TournamentStore_TournamentUpdated;
|
||||
}
|
||||
_tournamentStore.TournamentDeleted += TournamentStore_TournamentDeleted;
|
||||
}
|
||||
|
||||
public static OverviewListingViewModel LoadViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
|
||||
{
|
||||
OverviewListingViewModel viewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
||||
|
||||
viewModel.LoadTournamentsCommand.Execute(null);
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
protected override void Dispose()
|
||||
{
|
||||
_tournamentStore.TournamentLoaded -= TournamentStore_TournamentLoaded;
|
||||
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
|
||||
_tournamentStore.TournamentUpdated -= TournamentStore_TournamentUpdated;
|
||||
_tournamentStore.TournamentDeleted -= TournamentStore_TournamentDeleted;
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private void TournamentStore_TournamentLoaded()
|
||||
{
|
||||
_overviewListingItemViewModels.Clear();
|
||||
|
||||
foreach (Tournament tournament in _tournamentStore.Tournaments)
|
||||
{
|
||||
AddTournament(tournament);
|
||||
}
|
||||
}
|
||||
|
||||
private void TournamentStore_TournamentAdded(Tournament tournament)
|
||||
{
|
||||
AddTournament(tournament);
|
||||
@@ -64,7 +91,7 @@ namespace Apollon.WPF.ViewModels
|
||||
private void TournamentStore_TournamentUpdated(Tournament tournament)
|
||||
{
|
||||
OverviewListingItemViewModel overviewViewModel =
|
||||
_overviewListingItemViewModels.FirstOrDefault(y => y.Tournament.Id == tournament.Id);
|
||||
_overviewListingItemViewModels.FirstOrDefault(y => y.Tournament?.Id == tournament.Id);
|
||||
|
||||
if(overviewViewModel != null)
|
||||
{
|
||||
@@ -72,10 +99,21 @@ namespace Apollon.WPF.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private void TournamentStore_TournamentDeleted(Guid id)
|
||||
{
|
||||
OverviewListingItemViewModel itemViewModel = _overviewListingItemViewModels.FirstOrDefault(y => y.Tournament?.Id == id);
|
||||
|
||||
if (itemViewModel != null)
|
||||
{
|
||||
_overviewListingItemViewModels.Remove(itemViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddTournament(Tournament tournament)
|
||||
{
|
||||
OverviewListingItemViewModel itemViewModel = new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
|
||||
OverviewListingItemViewModel itemViewModel =
|
||||
new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
|
||||
_overviewListingItemViewModels.Add(itemViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Apollon.WPF.ViewModels
|
||||
|
||||
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
||||
OverviewListingViewModel = OverviewListingViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
||||
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
||||
|
||||
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
||||
|
||||
Reference in New Issue
Block a user