Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteEntity(int matchId)
        {
            try
            {
                await _matchService.DeleteEntity(matchId);

                return(Ok());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 3
0
 public IActionResult Delete(int id)
 {
     _matchService.DeleteEntity(id);
     return(Ok());
 }