deleted still shows on the details panel

This commit is contained in:
Natlinux81
2022-08-20 21:01:38 +02:00
parent 7313cc9a21
commit 6b0057b68a
10 changed files with 166 additions and 20 deletions

View File

@@ -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;
}
}
}
}

View File

@@ -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);
}
}
}