示例#1
0
        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());
        }
示例#2
0
        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());
        }