public async Task <IActionResult> EditRplyById(int id, [FromBody] MessageEditAPIModel msgModel) { if (ModelState.IsValid) { // get user (this ensures a bad user cannot edit another person's msg) var user = await userRepo.GetUserDataAsync(HttpContext.User); // find msg var foundRply = user.GetReplyHistory.Find(rply => rply.ReplyID == id); if (foundRply == null) { return(NotFound()); } // update msg foundRply.ReplyContent = msgModel.MsgBody; await replyRepo.UpdateRplyById(foundRply); // return msg return(Ok(foundRply)); } return(BadRequest()); }
public async Task <IActionResult> EditMsgById(int id, [FromBody] MessageEditAPIModel msgModel) { if (ModelState.IsValid) { // get user (this ensures a bad user cannot edit another person's msg) var user = await userRepo.GetUserDataAsync(HttpContext.User); // find msg var foundMsg = user.GetMessageList.Find(msg => msg.MessageID == id); if (foundMsg == null) { return(NotFound()); } // update msg foundMsg.MessageTitle = msgModel.MsgTitle; foundMsg.MessageContent = msgModel.MsgBody; await messageRepo.UpdateMsgById(foundMsg); // return msg return(Ok(foundMsg)); } return(BadRequest()); }