Esempio n. 1
0
        public void Execute()
        {
            var post = Session.Load<Post>(_postId);
            var comments = Session.Load<PostComments>(_postId);

            var comment = new PostComments.Comment
            {
                Id = comments.GenerateNewCommentId(),
                Author = _commentInput.Name,
                Body = _commentInput.Body,
                CreatedAt = DateTimeOffset.Now,
                Email = _commentInput.Email,
                Url = _commentInput.Url,
                Important = _requestValues.IsAuthenticated,
                UserAgent = _requestValues.UserAgent,
                UserHostAddress = _requestValues.UserHostAddress
            };
            comment.IsSpam = new AskimetService(Session).CheckForSpam(comment);

            if (comment.IsSpam)
                comments.Spam.Add(comment);
            else
            {
                post.CommentsCount++;
                comments.Comments.Add(comment);
            }

            SendNewCommentEmail(post, comment);
        }
Esempio n. 2
0
        public override void Execute()
        {
            var post = DocumentSession
                .Include<Post>(x => x.AuthorId)
                .Include(x => x.CommentsId)
                .Load(postId);
            var postAuthor = DocumentSession.Load<User>(post.AuthorId);
            var comments = DocumentSession.Load<PostComments>(post.CommentsId);

            var comment = new PostComments.Comment
                          	{
                          		Id = comments.GenerateNewCommentId(),
                          		Author = commentInput.Name,
                          		Body = commentInput.Body,
                          		CreatedAt = DateTimeOffset.Now,
                          		Email = commentInput.Email,
                          		Url = commentInput.Url,
                          		Important = requestValues.IsAuthenticated, // TODO: Don't mark as important based on that
                          		UserAgent = requestValues.UserAgent,
                          		UserHostAddress = requestValues.UserHostAddress
                          	};
            comment.IsSpam = AkismetService.CheckForSpam(comment);

            var commenter = DocumentSession.GetCommenter(commentInput.CommenterKey) ?? new Commenter { Key = commentInput.CommenterKey ?? Guid.Empty };

            if (requestValues.IsAuthenticated == false && comment.IsSpam)
            {
                if (commenter.NumberOfSpamComments > 4)
                    return;
                comments.Spam.Add(comment);
            }
            else
            {
                post.CommentsCount++;
                comments.Comments.Add(comment);
            }

            SetCommenter(commenter, comment.IsSpam);

            SendNewCommentEmail(post, comment, postAuthor);
        }
Esempio n. 3
0
        public void Execute()
        {
            var post = Session.Load<Post>(_postId);
            var comments = Session.Load<PostComments>(_postId);

            var comment = new PostComments.Comment
                          	{
                          		Id = comments.GenerateNewCommentId(),
                          		Author = _commentInput.Name,
                          		Body = _commentInput.Body,
                          		CreatedAt = DateTimeOffset.Now,
                          		Email = _commentInput.Email,
                          		Url = _commentInput.Url,
                          		Important = _requestValues.IsAuthenticated,
                          		UserAgent = _requestValues.UserAgent,
                          		UserHostAddress = _requestValues.UserHostAddress
                          	};
            comment.IsSpam = new AskimetService(Session).CheckForSpam(comment);

            var commenter = Session.GetCommenter(_commentInput.CommenterKey) ?? new Commenter { Key = _commentInput.CommenterKey ?? Guid.Empty };

            if (_requestValues.IsAuthenticated == false && comment.IsSpam)
            {
                if (commenter.NumberOfSpamComments > 4)
                    return;
                comments.Spam.Add(comment);
            }
            else
            {
                post.CommentsCount++;
                comments.Comments.Add(comment);
            }

            SetCommenter(commenter, comment.IsSpam);

            SendNewCommentEmail(post, comment);
        }
		public void CanMapFromCommentToNewCommentViewModel()
		{
			var comment = new PostComments.Comment();
			Assert.DoesNotThrow(() => comment.MapTo<NewCommentEmailViewModel>());
		}