Example #1
0
        public void AddPost(Area area, Post post, User creator, out ValidationStateDictionary validationState, out Post newPost)
        {
            validationState = new ValidationStateDictionary();

            post.Area    = area;
            post.Creator = creator;

            validationState.Add(typeof(Post), validator.Validate(post));

            if (!validationState.IsValid)
            {
                newPost = null;

                return;
            }

            repository.Save(post);

            if (post.Published.HasValue)
            {
                string postUrl = absolutePathHelper.GetAbsolutePath(post);
                IEnumerable <TrackbackOutbound> trackbacks = extractTrackbacks(post, postUrl, area.DisplayName);

                repository.SaveTrackbacks(trackbacks);
            }

            if (site.AuthorAutoSubscribe && !repository.GetSubscriptionExists(post, creator))
            {
                repository.AddSubscription(post, creator);
            }

            newPost = repository.GetPost(post.ID);
        }
Example #2
0
        public void AddPost(Post post, User creator, bool fireEvents, out ValidationStateDictionary validationState, out Post newPost)
        {
            validationState = new ValidationStateDictionary();

            post.Creator = creator;

            validationState.Add(typeof(Post), validator.Validate(post));

            if (!validationState.IsValid)
            {
                newPost = null;

                return;
            }

            if (fireEvents)
            {
                events.FireEvent("PostSaving", post);
            }

            repository.Save(post);

            newPost = repository.GetPost(post.ID);

            if (site.AuthorAutoSubscribe && !repository.GetSubscriptionExists(newPost, creator))
            {
                repository.AddSubscription(newPost, creator);
            }

            if (fireEvents)
            {
                events.FireEvent("PostSaved", newPost);
            }
        }
Example #3
0
 private void addCreatorSubscription(Post post)
 {
     if (context.Site.AuthorAutoSubscribe)
     {
         repository.AddSubscription(post, post.Creator.ID);
     }
 }
Example #4
0
        public void AddPost(Post post, User creator, out ValidationStateDictionary validationState, out Post newPost)
        {
            validationState = new ValidationStateDictionary();

            post.Creator = creator;

            validationState.Add(typeof(Post), validator.Validate(post));

            if (!validationState.IsValid)
            {
                newPost = null;

                return;
            }

            repository.Save(post);

            newPost = repository.GetPost(post.ID);

            if (site.AuthorAutoSubscribe && !repository.GetSubscriptionExists(newPost, creator))
            {
                repository.AddSubscription(newPost, creator);
            }

            if (post.Published.HasValue)
            {
                string postUrl = absolutePathHelper.GetAbsolutePath(post);
                IEnumerable <TrackbackOutbound> trackbacksToAdd    = extractTrackbacks(post, postUrl, post.Area.DisplayName);
                IEnumerable <TrackbackOutbound> unsentTrackbacks   = trackbackOutboundRepository.GetUnsent(post.ID);
                IEnumerable <TrackbackOutbound> trackbacksToRemove = trackbacksToAdd.Where(tb => !unsentTrackbacks.Contains(tb) && !tb.Sent.HasValue);

                trackbackOutboundRepository.Remove(trackbacksToRemove);
                trackbackOutboundRepository.Save(trackbacksToAdd);
            }
            else
            {
                //TODO: (erikpo) Remove all outbound trackbacks
            }
        }
Example #5
0
 public void AddSubscription(global::Oxite.Models.Post post, global::Oxite.Models.UserBase user)
 {
     inner.AddSubscription(post, user);
 }
Example #6
0
        public ModelResult <PostComment> AddComment(PostAddress postAddress, CommentInput commentInput)
        {
            CommentIn commentIn = new CommentIn(commentInput);

            pluginEngine.ExecuteAll("ProcessInputOfComment", new { context, comment = commentIn });
            commentInput = commentIn.ToCommentInput();

            commentInput = pluginEngine.Process("ProcessInputOfCommentOnAdd", new CommentIn(commentInput)).ToCommentInput();

            if (pluginEngine.AnyTrue("IsCommentSpam", new { context, comment = commentIn }))
            {
                return(new ModelResult <PostComment>(new ValidationStateDictionary(typeof(CommentInput), new ValidationState(new[] { new ValidationError("Comment.IsSpam", commentInput, "The supplied comment was considered to be spam and was not added") }))));
            }

            ValidationStateDictionary validationState = ValidateCommentInput(commentInput);

            if (!validationState.IsValid)
            {
                return(new ModelResult <PostComment>(validationState));
            }

            EntityState commentState;

            try
            {
                commentState = context.User.IsAuthenticated ? EntityState.Normal : (EntityState)Enum.Parse(typeof(EntityState), context.Site.CommentStateDefault);
            }
            catch
            {
                commentState = EntityState.PendingApproval;
            }

            //TODO: (erikpo) Replace with some logic to set the language from the user's browser or from a dropdown list
            Language    language = languageRepository.GetLanguage(context.Site.LanguageDefault ?? "en");
            PostComment comment;

            using (TransactionScope transaction = new TransactionScope())
            {
                string commentSlug = generateUniqueCommentSlug(postAddress);

                comment = commentInput.ToComment(context.User.Cast <UserAuthenticated>(), context.HttpContext.Request.GetUserIPAddress().ToLong(), context.HttpContext.Request.UserAgent, language, commentSlug, commentState);

                comment = blogsCommentRepository.Save(comment, context.Site.ID, postAddress.BlogName, postAddress.PostSlug);

                if (comment.State == EntityState.Normal)
                {
                    invalidateCachedCommentDependencies(comment);
                }

                transaction.Complete();
            }

            //TODO: (erikpo) The following calls to setup the subscription and send out emails for those subscribed needs to happen in the transaction (but can't currently because of issues with them being in different repositories

            //TODO: (erikpo) Move into a module
            if (commentInput.Subscribe)
            {
                if (context.User.IsAuthenticated)
                {
                    postRepository.AddSubscription(context.Site.ID, comment.Post, comment.CreatorUserID);
                }
                else
                {
                    postRepository.AddSubscription(context.Site.ID, comment);
                }
            }

            //TODO: (erikpo) Move into a module
            messageOutboundRepository.Save(generateMessages(comment.Post, comment));

            PostSmallReadOnly postProxy    = new PostSmallReadOnly(comment.Post);
            CommentReadOnly   commentProxy = new CommentReadOnly(comment, absolutePathHelper.GetAbsolutePath(comment));

            pluginEngine.ExecuteAll("CommentAdded", new { context, parent = postProxy, comment = commentProxy });

            if (comment.State == EntityState.Normal)
            {
                pluginEngine.ExecuteAll("CommentApproved", new { context, parent = postProxy, comment = commentProxy });
            }

            return(new ModelResult <PostComment>(comment, validationState));
        }