public async Task <IActionResult> UpdateMessage([FromBody] MessageForUpdateDto messageForUpdateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var userFromRepo = await _repo.GetUser(currentUserId); if (userFromRepo == null) { return(Unauthorized()); } var messageFromRepo = await _repo.GetMessage(messageForUpdateDto.Id, currentUserId); _mapper.Map(messageForUpdateDto, messageFromRepo); await _repo.SaveAll(); var messageForReturn = _mapper.Map <MessageForDetailedDto>(messageFromRepo); return(Ok(messageForReturn)); }
public IActionResult UpdateMessage([FromBody] JObject message, string messageid) { try { var messageEntity = _messageInfoRepository.GetMessagesByTypes(MessageTypes.MessageId, messageid); MessageForUpdateDto messageobj = message.ToObject <MessageForUpdateDto>(); Mapper.Map(messageobj, messageEntity); if (!_messageInfoRepository.Save()) { return(StatusCode(500, new UploadeResponse { Success = false, ErrorDescription = "Error while updating message" })); } return(Ok(messageEntity)); } catch (Exception ex) { _logger.LogCritical($"Exception while updating message.", ex); return(StatusCode(500, "A problem happened while handling your request.")); } }
public IActionResult UpdateMessage(int id, [FromBody] MessageForUpdateDto message) { if (message == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var messageFromStore = MessagesDataStore.Current.Messages.FirstOrDefault(m => m.Id == id); if (messageFromStore == null) { return(NotFound()); } messageFromStore.Message = message.Message; return(NoContent()); }