Пример #1
0
 public ActionResult <RoundDto> UpdateRound([FromRoute] int id, [FromBody] RoundDto roundDto)
 {
     try
     {
         var round = new RoundMapper().ToModel(roundDto);
         round.RoundId ??= id;
         var result = _unitOfWork.Rounds.Update(id, round);
         _unitOfWork.Save();
         return(Ok(new RoundMapper().ToDto(result)));
     }
     catch (Exception e)
     {
         throw new HttpRequestException(e.Message, e, HttpStatusCode.InternalServerError);
     }
 }
Пример #2
0
 public ActionResult <RoundDto> CreateRound([FromBody] RoundDto roundDto)
 {
     try
     {
         if (roundDto is null)
         {
             return(BadRequest("Round can't be null"));
         }
         var round = new RoundMapper().ToModel(roundDto);
         var send  = _unitOfWork.Rounds.Add(round);
         _unitOfWork.Save();
         var dto = new RoundMapper().ToDto(send);
         return(CreatedAtAction(nameof(GetRoundById), new { id = dto.RoundId }, dto));
     }
     catch (Exception e)
     {
         throw new HttpRequestException(e.Message, e, HttpStatusCode.InternalServerError);
     }
 }