Exemplo n.º 1
0
        public IActionResult ChangeCommentText([FromBody] ChangeCommentTextModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest("Cannot update comment. Data are invalid"));
            }

            var currentUserId = HttpContext.User
                                .Claims?
                                .FirstOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier)?
                                .Value ?? string.Empty;

            var commentOwnerId = _commentManager.GetCommentOwner(model.CommentId);

            if (commentOwnerId != currentUserId)
            {
                return(StatusCode(403, new { message = "Invalid user id" }));
            }

            var(success, message) = _commentManager
                                    .UpdateComment(model.CommentId, model.CommentText);

            if (success)
            {
                return(Ok(new { message }));
            }

            return(BadRequest(new { message }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ConfirmEditComment(UpdateCommentViewModel comment)
        {
            var commentDto = Mapper.Map <CommentDto>(comment);

            commentDto.User = User.CreateUserDto();
            await _commentManager.UpdateComment(commentDto);

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
 public IActionResult Put(int id, [FromBody] Comment comment)
 {
     try
     {
         _commentManager.UpdateComment(id, comment);
         return(Ok());
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
 }