public async Task <ActionResult> UpdateMatch(BilliardsMatchDto billiardsMatchDto) { var match = await unitOfWork.BilliardsGameRepository.GetSingleMatchAsync(billiardsMatchDto.Id); if (match == null) { return(BadRequest("Match does not exist.")); } mapper.Map(billiardsMatchDto, match); unitOfWork.BilliardsGameRepository.UpdateMatch(match); if (await unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Update failed.")); }
public async Task <ActionResult> InsertMatch(BilliardsMatchDto billiardsMatchDto) { var type = await unitOfWork.BilliardsMatchTypesRepository.GetMatchTypeByIdAsync(billiardsMatchDto.TypeId); if (type == null) { return(BadRequest("Invalid type.")); } var tournament = await unitOfWork.BilliardsTournamentRepository.GetTournamentById(billiardsMatchDto.TournamentId); if (tournament == null) { return(BadRequest("Invalid tournament.")); } // check if season is done by checking if all type for tournament and season has final mode // if (await unitOfWork.BilliardsGameRepository.CheckIfSeasonIsDone(billiardsMatchDto.SeasonNumberId)) // return BadRequest("This season is done. You cannot edit it anymore."); // before insert, check first if the final mode is already inserted for the type, season and tournament var lastMode = await unitOfWork.BilliardsModeRepository.GetTournamentLastModeAsync(tournament.Id); // check if last mode is already inserted to prevent new matches var history = await unitOfWork.BilliardsGameRepository.CheckIfLastModeIsPlayed(lastMode.ModeId, billiardsMatchDto.SeasonNumberId, billiardsMatchDto.TournamentId, billiardsMatchDto.TypeId); if (history != null) { return(BadRequest("Cannot insert anymore to " + type.Type + " for this season")); } unitOfWork.BilliardsGameRepository.InsertMatch(mapper.Map <BilliardsMatch>(billiardsMatchDto)); if (await unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Insert failed.")); }