예제 #1
0
        public async Task <BlogCommentViewModel> Add(BlogCommentViewModel blogCommentVm)
        {
            var page = new BlogCommentViewModel().Map(blogCommentVm);
            await _blogCommentRepository.Add(page);

            _unitOfWork.Commit();
            return(blogCommentVm);
        }
        /// <summary>
        /// Adds the comment in the CommentFormViewModel to the Episerver Social repository.
        /// </summary>
        /// <param name="formViewModel">The submitted comment form view model.</param>
        /// <returns>The added PageComment</returns>
        private BlogComment AddComment(BlogCommentFormViewModel formViewModel)
        {
            var         newComment   = AdaptCommentFormViewModelToSocialComment(formViewModel);
            BlogComment addedComment = null;

            try
            {
                addedComment = _commentRepository.Add(newComment);
                AddMessage(MessageKey, SubmitSuccessMessage);
            }
            catch (Exception ex)
            {
                AddMessage(MessageKey, ex.Message);
            }

            return(addedComment);
        }
        public IActionResult Add([FromBody] AddBlogCommentVModel param)
        {
            var result = new ResultModel();

            return(this.Wrapper(ref result, () =>
            {
                result = _blogCommentRepository.Add(new HeyTom.MyBlog.Model.BlogComment()
                {
                    BlogId = param.blogId,
                    UserId = param.userId,
                    BackId = param.backId,
                    BackUserId = param.backuserId,
                    BackUserName = param.backuserName,
                    Content = param.content,
                    CreateDate = DateTime.Now,
                    UserName = param.userName
                });
            }, true));
        }
        public HttpResponseMessage SubmitComment(HttpRequestMessage request, [FromBody] BlogComment blogComment)
        {
            HttpResponseMessage response = null;

            try
            {
                blogComment.Timestamp = DateTime.Now;

                PreSubmissionCommentEventArgs preArgs = new PreSubmissionCommentEventArgs(blogComment);

                _ExtensibilityManager.InvokeCancelableModuleEvent <PreSubmissionCommentEventArgs>(
                    _ModuleEvents.PreSubmissionComment, preArgs);

                if (!preArgs.Cancel)
                {
                    IBlogCommentRepository blogCommentRepository = _componentLocator.ResolveComponent <IBlogCommentRepository>();

                    blogComment.CommentBody = preArgs.CommentReplacement;
                    blogComment             = blogCommentRepository.Add(blogComment);

                    PostSubmissionCommentEventArgs postArgs = new PostSubmissionCommentEventArgs(blogComment);

                    _ExtensibilityManager.InvokeModuleEvent <PostSubmissionCommentEventArgs>(
                        _ModuleEvents.PostSubmissionComment, postArgs);

                    response = request.CreateResponse <BlogComment>(HttpStatusCode.OK, blogComment);
                }
                else
                {
                    throw new ApplicationException("Comment submission has been blocked.");
                }
            }
            catch (Exception ex)
            {
                response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return(response);
        }