Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateCommentAsync([FromRoute] int postId, [FromRoute]  int commentId, [FromBody] CommentUpdateModel model)
        {
            var comment = await _postRepository.GetCommentByIdAsync(commentId);

            if (!await _postRepository.AnyByIdAsync(postId))
            {
                throw new NotFound404Exception("post");
            }

            if (comment == null)
            {
                throw new NotFound404Exception("comment");
            }

            if (string.IsNullOrWhiteSpace(model.Content))
            {
                throw new IsRequiredException("content");
            }

            if (model.Content.Length < 20)
            {
                throw new ContentIsInvalidException();
            }

            // bind data
            comment.Content     = model.Content;
            comment.UpdatedDate = DateTime.Now;

            await _postRepository.UpdateCommentAsync(comment);

            return(Ok(CommentDTO.GetFrom(comment)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateComment(int id, [FromBody] CommentUpdateModel model)
        {
            await _commentService.UpdateComment(id, _mapper.Map <CommentDTO>(model), Request.GetToken());

            return(NoContent());
        }
Ejemplo n.º 3
0
 public Task <IResultModel> Update(CommentUpdateModel model)
 {
     return(_service.Update(model));
 }
Ejemplo n.º 4
0
 public async Task UpdateCommentAsync(CommentUpdateModel model)
 {
     var commentDTO = _mapper.Map <CommentDTO>(model);
     await _commentService.UpdateCommentAsync(commentDTO);
 }