deleted still shows on the details panel
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user