public async Task DeleteEntity(int teamId) { Team team = await _repository.QueryByIdAsync <Team>(teamId); if (team == null) { throw new InvalidOperationException($"Team with id {teamId} not found."); } var matches = await _matchService.GetEntities(); var teamMatches = matches.Where(m => m.HomeTeamId == teamId || m.AwayTeamId == teamId); var players = await _playerService.GetEntitiesByTeamId(teamId); foreach (var player in players) { await _playerService.DeleteEntity(player.Id); } foreach (var match in teamMatches) { await _matchService.DeleteEntity(match.Id); } await _repository.DeleteAsync <Team>(teamId); }
public async Task <IActionResult> DeleteEntity(int matchId) { try { await _matchService.DeleteEntity(matchId); return(Ok()); } catch (Exception e) { Console.WriteLine(e); return(BadRequest(e.Message)); } }
public IActionResult Delete(int id) { _matchService.DeleteEntity(id); return(Ok()); }