public ActionResult Comment(CommentInput input, int id, Guid showPostEvenIfPrivate)
        {
            var post = RavenSession
                .Include<Post>(x => x.CommentsId)
                .Load(id);

            if (post == null || post.IsPublicPost(showPostEvenIfPrivate) == false)
                return HttpNotFound();

            var comments = RavenSession.Load<PostComments>(post.CommentsId);
            if (comments == null)
                return HttpNotFound();

            var commenter = RavenSession.GetCommenter(input.CommenterKey);
            if (commenter == null)
            {
                input.CommenterKey = Guid.NewGuid();
            }

            ValidateCommentsAllowed(post, comments);
            ValidateCaptcha(input, commenter);

            if (ModelState.IsValid == false)
                return PostingCommentFailed(post, input, showPostEvenIfPrivate);

            TaskExecutor.ExcuteLater(new AddCommentTask(input, Request.MapTo<AddCommentTask.RequestValues>(), id));

            CommenterUtil.SetCommenterCookie(Response, input.CommenterKey.MapTo<string>());

            return PostingCommentSucceeded(post);
        }
        public ActionResult Comment(CommentInput input, int id, Guid key)
        {
            var post = Session
                .Include<Post>(x => x.CommentsId)
                .Load(id);

            if (post == null || post.IsPublicPost(key) == false)
                return HttpNotFound();

            var comments = Session.Load<PostComments>(post.CommentsId);
            if (comments == null)
                return HttpNotFound();

            var commenter = Session.GetCommenter(input.CommenterKey);
            if (commenter == null)
            {
                input.CommenterKey = Guid.NewGuid().MapTo<string>();
            }

            ValidateCommentsAllowed(post, comments);
            ValidateCaptcha(input, commenter);

            if (ModelState.IsValid == false)
                return PostingCommentFailed(post, input, key);

            CommandExecutor.ExcuteLater(new AddCommentCommand(input, Request.MapTo<RequestValues>(), id));

            SetCommenterCookie(input);

            return PostingCommentSucceeded(post);
        }
		public virtual ActionResult Comment(CommentInput input, int id, Guid key)
		{
		    if (ModelState.IsValid)
		    {
                var post = RavenSession
                    .Include<Post>(x => x.CommentsId)
                    .Load(id);

                if (post == null || post.IsPublicPost(key) == false)
                    return HttpNotFound();

                var comments = RavenSession.Load<PostComments>(post.CommentsId);
                if (comments == null)
                    return HttpNotFound();

                var commenter = RavenSession.GetCommenter(input.CommenterKey);
                if (commenter == null)
                {
                    input.CommenterKey = Guid.NewGuid();
                }

                ValidateCommentsAllowed(post, comments);
                ValidateCaptcha(input, commenter);

                if (ModelState.IsValid == false)
                    return PostingCommentFailed(post, input, key);

                TaskExecutor.ExcuteLater(new AddCommentTask(input, Request.MapTo<AddCommentTask.RequestValues>(), id));

                CommenterUtil.SetCommenterCookie(Response, input.CommenterKey.MapTo<string>());

				OutputCacheManager.RemoveItem(SectionController.NameConst, MVC.Section.ActionNames.List);

                return PostingCommentSucceeded(post, input);
		    }

		    return RedirectToAction("Details");
		}
        private ActionResult PostingCommentFailed(Post post, CommentInput input, Guid key)
        {
            if (Request.IsAjaxRequest())
                return Json(new {Success = false, message = ModelState.FirstErrorMessage()});

            var postReference = post.MapTo<PostReference>();
            var result = Details(postReference.DomainId, postReference.Slug, key);
            var model = result as ViewResult;
            if (model != null)
            {
                var viewModel = model.Model as PostViewModel;
                if (viewModel != null)
                    viewModel.Input = input;
            }
            return result;
        }
        private void ValidateCaptcha(CommentInput input, Commenter commenter)
        {
            if (Request.IsAuthenticated ||
                (commenter != null && commenter.IsTrustedCommenter == true))
                return;

            if (RecaptchaValidatorWrapper.Validate(ControllerContext.HttpContext))
                return;

            ModelState.AddModelError("CaptchaNotValid",
                                     "You did not type the verification word correctly. Please try again.");
        }
 private void SetCommenterCookie(CommentInput commentInput)
 {
     var cookie = new HttpCookie(CommenterCookieName, commentInput.CommenterKey)
     {
         Expires = DateTime.Now.AddYears(1)
     };
     Response.Cookies.Add(cookie);
 }
 public AddCommentCommand(CommentInput commentInput, RequestValues requestValues, int postId)
 {
     _commentInput = commentInput;
     _requestValues = requestValues;
     _postId = postId;
 }
		private ActionResult PostingCommentSucceeded(Post post, CommentInput input)
		{
			const string successMessage = "Your comment will be posted soon. Thanks!";
			if (Request.IsAjaxRequest())
				return Json(new {Success = true, message = successMessage});

			TempData["new-comment"] = input;
			var postReference = post.MapTo<PostReference>();

			return Redirect(Url.Action("Details",
				new { Id = postReference.DomainId, postReference.Slug, key = post.ShowPostEvenIfPrivate }) + "#comments-form-location");
		}
Beispiel #9
0
		public AddCommentTask(CommentInput commentInput, RequestValues requestValues, int postId)
		{
			this.commentInput = commentInput;
			this.requestValues = requestValues;
			this.postId = postId;
		}