public ModelResult <Post> AddPost(PostInput postInput, EntityState postState)
        {
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPost", new PluginPostInput(postInput)).ToPostInput();
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPostOnAdd", new PluginPostInput(postInput)).ToPostInput();

            ModelResult <Post> results = addPost(postInput, () => postInput.ToPost(postState, context.User.Cast <User>(), t => expressions.Clean("TagReplace", t)));

            if (results.IsValid)
            {
                Post   newPost = results.Item;
                string postUrl = urlHelper.AbsolutePath(urlHelper.Post(newPost));

                //TODO: (erikpo) Move this into a module
                addCreatorSubscription(newPost);

                //TODO: (erikpo) Move this into a module
                if (newPost.State == EntityState.Normal && newPost.Published.HasValue)
                {
                    IEnumerable <TrackbackOutbound> trackbacksToAdd    = extractTrackbacks(newPost, postUrl, newPost.Blog.DisplayName);
                    IEnumerable <TrackbackOutbound> unsentTrackbacks   = trackbackOutboundRepository.GetUnsent(newPost.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
                }

                pluginEngine.ExecuteAll("PostSaved", new { context, post = new PostReadOnly(newPost, postUrl) });
                pluginEngine.ExecuteAll("PostAdded", new { context, post = new PostReadOnly(newPost, postUrl) });

                if (newPost.State == EntityState.Normal && newPost.Published.HasValue && newPost.Published.Value <= DateTime.UtcNow)
                {
                    pluginEngine.ExecuteAll("PostPublished", new { context, post = new PostReadOnly(newPost, postUrl) });
                }
            }

            return(results);
        }
Exemple #2
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
            }
        }
 public void Remove(IEnumerable <TrackbackOutbound> trackbacks)
 {
     repository.Remove(trackbacks);
 }