Example #1
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().ToString(),
                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
            };

            SetCommenter(commenter, comment);

            if (requestValues.IsAuthenticated == false && comment.IsSpam)
            {
                if (commenter.NumberOfSpamComments > 4)
                {
                    return;
                }

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

            SendNewCommentEmail(post, comment, postAuthor);
        }