Exemple #1
0
        public async Task <ActionResult> CreateComment(int postId, string text)
        {
            var commentVm = new CommentViewModel();

            commentVm.Text = text;
            commentVm.User = new UserViewModel {
                UserName = System.Web.HttpContext.Current.User.Identity.Name
            };

            await service.AddCommentAsync(postId, commentVm.ToDto());

            return(RedirectToAction(Constant.View.GetPost, Constant.View.Post, new { postId = postId }));
        }
        public IHttpActionResult Create([FromBody] CommentViewModel data)
        {
            return(PerformAction <CommentDto>(() =>
            {
                CommentDto result = null;

                var comment = data
                              .ToDto();

                if (comment != null)
                {
                    comment.UserId = GetCurrentUserId();

                    result = _commentService
                             .Create(comment);
                }

                return result;
            }));
        }
        public IHttpActionResult Update(int id, [FromBody] CommentViewModel data)
        {
            return(PerformAction <CommentDto>(() =>
            {
                CommentDto result = null;

                var ctx = GetPermissionsContext();

                var commentDto = _commentService
                                 .Get(ctx, id);

                if (commentDto != null)
                {
                    commentDto = data
                                 .ToDto(commentDto);

                    result = _commentService
                             .Update(commentDto);
                }

                return result;
            }));
        }
Exemple #4
0
        public async Task <ActionResult> ChangeComment(CommentViewModel comment)
        {
            await service.ChangeCommentAsync(comment.Id, comment.ToDto());

            return(RedirectToAction(Constant.View.GetPost, Constant.View.Post, new { postId = comment.Post.Id }));
        }