コード例 #1
0
 /// <summary>
 /// Adapts a CommentFormViewModel to a PageComment.
 /// </summary>
 /// <param name="formViewModel">The comment form view model.</param>
 /// <returns>PageComment</returns>
 private BlogComment AdaptCommentFormViewModelToSocialComment(BlogCommentFormViewModel formViewModel)
 {
     return(new BlogComment
     {
         Target = _pageRepository.GetPageId(formViewModel.CurrentPageLink),
         Name = formViewModel.Name,
         Email = formViewModel.Email,
         Body = formViewModel.Body
     });
 }
コード例 #2
0
        public ActionResult Submit(BlogCommentFormViewModel formViewModel)
        {
            var errors = ValidateCommentForm(formViewModel);

            if (errors.Count() == 0)
            {
                var addedComment = AddComment(formViewModel);
            }
            else
            {
                // Flag the CommentBody model state with validation error
                AddMessage(MessageKey, errors.First());
            }

            return(Redirect(UrlResolver.Current.GetUrl(formViewModel.CurrentPageLink)));
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// Validates the comment form.
        /// </summary>
        /// <param name="formViewModel">The comment form view model.</param>
        /// <returns>Returns a list of validation errors.</returns>
        private List <string> ValidateCommentForm(BlogCommentFormViewModel formViewModel)
        {
            var errors = new List <string>();

            // Make sure the comment name has some text
            if (string.IsNullOrWhiteSpace(formViewModel.Name))
            {
                errors.Add(NameValidationErrorMessage);
            }

            // Make sure the comment email has some text
            if (string.IsNullOrWhiteSpace(formViewModel.Email))
            {
                errors.Add(EmailValidationErrorMessage);
            }

            // Make sure the comment body has some text
            if (string.IsNullOrWhiteSpace(formViewModel.Body))
            {
                errors.Add(BodyValidationErrorMessage);
            }

            return(errors);
        }