public async Task <ActionResult> InsertSeasonHistory(SeasonHistoryDto seasonHistoryDto) { if (await unitOfWork.BilliardsTournamentRepository.GetTournamentById(seasonHistoryDto.TournamentId) == null) { return(BadRequest("Invalid tournament.")); } if (await unitOfWork.UserRepository.GetUserByIdAsync(seasonHistoryDto.UserId) == null) { return(BadRequest("Invalid user.")); } var type = await unitOfWork.BilliardsMatchTypesRepository.GetMatchTypeByIdAsync(seasonHistoryDto.TypeId); if (type == null) { return(BadRequest("Invalid type.")); } if (await unitOfWork.BilliardsRepository.GetSeasonBySeasonNumberId(seasonHistoryDto.SeasonNumberId) == null) { return(BadRequest("Invalid season.")); } var mode = await unitOfWork.BilliardsModeRepository.GetModeByIdAsync(seasonHistoryDto.ModeId); if (mode == null) { return(BadRequest("Invalid mode.")); } var history = mapper.Map <SeasonHistory>(seasonHistoryDto); unitOfWork.SeasonHistoryRepository.InsertSeasonHistory(history); if (await unitOfWork.Complete()) { return(Ok()); } return(BadRequest("Error in season history insert.")); }
public async Task <ActionResult> InserSeasonHistory(SeasonHistoryDto seasonHistoryDto) { var season = await unitOfWork.BilliardsRepository.GetSeasonBySeasonNumber(seasonHistoryDto.SeasonNumber); if (season == null) { return(BadRequest("Invalid season.")); } var tournament = await unitOfWork.BilliardsTournamentRepository.GetTournamentById(seasonHistoryDto.TournamentId); if (tournament == null) { return(BadRequest("Invalid tournament.")); } var type = await unitOfWork.BilliardsMatchTypesRepository.GetMatchTypeByIdAsync(seasonHistoryDto.TypeId); if (type == null) { return(BadRequest("Invalid type.")); } var user = await unitOfWork.UserRepository.GetUserByIdAsync(seasonHistoryDto.UserId); if (user == null) { return(BadRequest("Invalid user.")); } unitOfWork.BilliardsRepository.InsertSeasonHistory(mapper.Map <SeasonHistory>(seasonHistoryDto)); if (await unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Insert failed.")); }