Exemplo n.º 1
0
        public ActionResult AddComment(CommentDto commentDto)
        {
            var list = new List <CommentViewModel>();

            try
            {
                var userId  = User.Identity.GetUserId();
                var comment = _repository.PostRepository.AddComment(commentDto.PostId, userId, commentDto.Text);
                list.Add(CommentViewModel.Create(comment, userId));
                _repository.Complete();
                list[0].Id = comment.Id;
                CommentsHub.Notify(commentDto.PostId, comment.Id);
            }
            catch (DbEntityValidationException exception)
            {
                list[0].Error = DbEntityValidationExceptionHandler.GetExceptionMessage(exception);
                return(PartialView("_CommentsList", list));
            }
            catch (Exception exception)
            {
                list[0].Error = exception.Message;
                return(PartialView("_CommentsList", list));
            }

            return(PartialView("_CommentsList", list));
        }