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)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Apollon.WPF.Commands
|
|||||||
await ExecuteAsync(parameter);
|
await ExecuteAsync(parameter);
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Task ExecuteAsync(object parameter);
|
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 OverviewListingItemViewModel _overviewListingItemViewModel;
|
||||||
private readonly TournamentsStore _tournamentStore;
|
private readonly TournamentsStore _tournamentStore;
|
||||||
|
|
||||||
public OpenEditTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
|
public OpenEditTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel,
|
||||||
|
TournamentsStore tournamentStore,
|
||||||
|
ModalNavigationStore modalNavigationStore)
|
||||||
{
|
{
|
||||||
_overviewListingItemViewModel = overviewListingItemViewModel;
|
_overviewListingItemViewModel = overviewListingItemViewModel;
|
||||||
_tournamentStore = tournamentStore;
|
_tournamentStore = tournamentStore;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Apollon.WPF.Stores
|
|||||||
{
|
{
|
||||||
private readonly TournamentsStore _tournamentStore;
|
private readonly TournamentsStore _tournamentStore;
|
||||||
|
|
||||||
private Tournament _selectedTournament;
|
private Tournament _selectedTournament;
|
||||||
|
|
||||||
public Tournament SelectedTournament
|
public Tournament SelectedTournament
|
||||||
{
|
{
|
||||||
@@ -42,5 +42,6 @@ namespace Apollon.WPF.Stores
|
|||||||
SelectedTournament = tournament;
|
SelectedTournament = tournament;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ namespace Apollon.WPF.Stores
|
|||||||
private readonly ICreateTournamentCommand _createTournamentCommand;
|
private readonly ICreateTournamentCommand _createTournamentCommand;
|
||||||
private readonly IUpdateTournamentCommand _updateTournamentCommand;
|
private readonly IUpdateTournamentCommand _updateTournamentCommand;
|
||||||
private readonly IDeleteTournamentCommand _deleteTournamentCommand;
|
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,
|
public TournamentsStore(IGetAllTournamentsQuery getAllTournamentQuery,
|
||||||
ICreateTournamentCommand createTournamentCommand,
|
ICreateTournamentCommand createTournamentCommand,
|
||||||
@@ -25,10 +33,19 @@ namespace Apollon.WPF.Stores
|
|||||||
_createTournamentCommand = createTournamentCommand;
|
_createTournamentCommand = createTournamentCommand;
|
||||||
_updateTournamentCommand = updateTournamentCommand;
|
_updateTournamentCommand = updateTournamentCommand;
|
||||||
_deleteTournamentCommand = deleteTournamentCommand;
|
_deleteTournamentCommand = deleteTournamentCommand;
|
||||||
|
|
||||||
|
_tournaments = new List<Tournament>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<Tournament> TournamentAdded;
|
public async Task Load()
|
||||||
public event Action<Tournament> TournamentUpdated;
|
{
|
||||||
|
IEnumerable<Tournament> tournaments = await _getAllTournamentQuery.Execute();
|
||||||
|
|
||||||
|
_tournaments.Clear();
|
||||||
|
_tournaments.AddRange(tournaments);
|
||||||
|
|
||||||
|
TournamentLoaded?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Add(Tournament tournament)
|
public async Task Add(Tournament tournament)
|
||||||
{
|
{
|
||||||
@@ -36,10 +53,31 @@ namespace Apollon.WPF.Stores
|
|||||||
TournamentAdded?.Invoke(tournament);
|
TournamentAdded?.Invoke(tournament);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update (Tournament tournament)
|
public async Task Update(Tournament tournament)
|
||||||
{
|
{
|
||||||
await _updateTournamentCommand.Execute(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);
|
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;
|
Tournament = tournament;
|
||||||
|
|
||||||
EditCommand = new OpenEditTournamentCommand(this, tournamentStore, modalNavigationStore);
|
EditCommand = new OpenEditTournamentCommand(this, tournamentStore, modalNavigationStore);
|
||||||
|
DeleteCommand = new DeleteTournamentCommand(this, tournamentStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(Tournament tournament)
|
public void Update(Tournament tournament)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ namespace Apollon.WPF.ViewModels
|
|||||||
private readonly ModalNavigationStore _modalNavigationStore;
|
private readonly ModalNavigationStore _modalNavigationStore;
|
||||||
private readonly TournamentsStore _tournamentStore;
|
private readonly TournamentsStore _tournamentStore;
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
|
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
|
||||||
|
|
||||||
private OverviewListingItemViewModel _selectedOverviewListingItemViewModel;
|
private OverviewListingItemViewModel _selectedOverviewListingItemViewModel;
|
||||||
@@ -38,6 +37,8 @@ namespace Apollon.WPF.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand LoadTournamentsCommand { get;}
|
||||||
|
|
||||||
public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
|
public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
|
||||||
{
|
{
|
||||||
_tournamentStore = tournamentStore;
|
_tournamentStore = tournamentStore;
|
||||||
@@ -45,17 +46,43 @@ namespace Apollon.WPF.ViewModels
|
|||||||
_modalNavigationStore = modalNavigationStore;
|
_modalNavigationStore = modalNavigationStore;
|
||||||
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
||||||
|
|
||||||
|
LoadTournamentsCommand = new LoadTournamentsCommand(tournamentStore);
|
||||||
|
|
||||||
|
_tournamentStore.TournamentLoaded += TournamentStore_TournamentLoaded;
|
||||||
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
|
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
|
||||||
_tournamentStore.TournamentUpdated += TournamentStore_TournamentUpdated;
|
_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()
|
protected override void Dispose()
|
||||||
{
|
{
|
||||||
|
_tournamentStore.TournamentLoaded -= TournamentStore_TournamentLoaded;
|
||||||
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
|
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
|
||||||
_tournamentStore.TournamentUpdated -= TournamentStore_TournamentUpdated;
|
_tournamentStore.TournamentUpdated -= TournamentStore_TournamentUpdated;
|
||||||
|
_tournamentStore.TournamentDeleted -= TournamentStore_TournamentDeleted;
|
||||||
|
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TournamentStore_TournamentLoaded()
|
||||||
|
{
|
||||||
|
_overviewListingItemViewModels.Clear();
|
||||||
|
|
||||||
|
foreach (Tournament tournament in _tournamentStore.Tournaments)
|
||||||
|
{
|
||||||
|
AddTournament(tournament);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void TournamentStore_TournamentAdded(Tournament tournament)
|
private void TournamentStore_TournamentAdded(Tournament tournament)
|
||||||
{
|
{
|
||||||
AddTournament(tournament);
|
AddTournament(tournament);
|
||||||
@@ -64,7 +91,7 @@ namespace Apollon.WPF.ViewModels
|
|||||||
private void TournamentStore_TournamentUpdated(Tournament tournament)
|
private void TournamentStore_TournamentUpdated(Tournament tournament)
|
||||||
{
|
{
|
||||||
OverviewListingItemViewModel overviewViewModel =
|
OverviewListingItemViewModel overviewViewModel =
|
||||||
_overviewListingItemViewModels.FirstOrDefault(y => y.Tournament.Id == tournament.Id);
|
_overviewListingItemViewModels.FirstOrDefault(y => y.Tournament?.Id == tournament.Id);
|
||||||
|
|
||||||
if(overviewViewModel != null)
|
if(overviewViewModel != null)
|
||||||
{
|
{
|
||||||
@@ -72,9 +99,20 @@ 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)
|
private void AddTournament(Tournament tournament)
|
||||||
{
|
{
|
||||||
OverviewListingItemViewModel itemViewModel = new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
|
OverviewListingItemViewModel itemViewModel =
|
||||||
|
new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
|
||||||
_overviewListingItemViewModels.Add(itemViewModel);
|
_overviewListingItemViewModels.Add(itemViewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Apollon.WPF.ViewModels
|
|||||||
|
|
||||||
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
|
||||||
{
|
{
|
||||||
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
OverviewListingViewModel = OverviewListingViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
|
||||||
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
||||||
|
|
||||||
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
||||||
|
|||||||
Reference in New Issue
Block a user