public async Task <PubDto> UpdatePub(PubDtoUpdate dto) { var userId = _userAccessor.GetCurrentUsername(); if (userId == null) { throw new RestExceptions(HttpStatusCode.NotAcceptable, new { User = "******" }); } if (dto == null) { throw new RestExceptions(HttpStatusCode.BadRequest, new { Pub = "Bad Request" }); } var userFromRepo = await _repository.GetPubById(dto.Id); if (int.Parse(userId) != userFromRepo.Id) { throw new RestExceptions(HttpStatusCode.Unauthorized, new { Pub = "You cannot modify" }); } _mapper.Map(dto, userFromRepo); var sucess = await _repository.UpdatePub(userFromRepo); if (sucess) { var result = _mapper.Map <Pub, PubDto>(userFromRepo); return(result); } throw new RestExceptions(HttpStatusCode.NotModified, new { Pub = $"Updating pub {dto.Id} failed" }); }
public async Task <IActionResult> UpdatePub(PubDtoUpdate pub) { var pubUpdated = await _services.UpdatePub(pub); return(Ok(pubUpdated)); }