public async Task <ResponseDto <BaseModelDto> > DeleteMatchAsync(int matchId) { var response = new ResponseDto <BaseModelDto>(); var match = _matchRepository.GetById(matchId); if (match == null) { response.Errors.Add(ServiceErrors.MATCH_DOES_NOT_EXIST); return(response); } var statisticsToDelete = new List <Statistic>(); foreach (var matchPlayer in match.MatchPlayers) { foreach (var stat in matchPlayer.Statistics) { statisticsToDelete.Add(stat); } } for (var i = statisticsToDelete.Count - 1; i >= 0; i--) { await _statisticRepository.DeleteAsync(statisticsToDelete[i]); } await _matchRepository.DeleteAsync(match); return(response); }
public async Task <ResponseDto <BaseModelDto> > DeleteAsync(int statisticId) { var response = new ResponseDto <BaseModelDto>(); var statistic = _statisticRepository.GetById(statisticId); if (statistic == null) { response.Errors.Add(ServiceErrors.STATISTIC_DOES_NOT_EXIST); return(response); } await _statisticRepository.DeleteAsync(statistic); return(response); }