コード例 #1
0
        public BlogPartHandler(IRepository<BlogPartRecord> repository, IWorkContextAccessor workContextAccessor, IEnumerable<IHomePageProvider> homePageProviders, IBlogPathConstraint blogPathConstraint)
        {
            _workContextAccessor = workContextAccessor;
            _blogPathConstraint = blogPathConstraint;
            _routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
            Filters.Add(StorageFilter.For(repository));

            Action<PublishContentContext, RoutePart> publishedHandler = (context, route) => {
                if (route.Is<BlogPart>()) {
                    if (route.ContentItem.Id != 0 && route.PromoteToHomePage)
                        _blogPathConstraint.AddPath("");
                }
                else if (route.ContentItem.Id != 0 && route.PromoteToHomePage) {
                    _blogPathConstraint.RemovePath("");
                }
            };

            OnPublished<RoutePart>(publishedHandler);
            OnUnpublished<RoutePart>(publishedHandler);

            OnGetDisplayShape<BlogPart>((context, blog) => {
                context.Shape.Description = blog.Description;
                context.Shape.PostCount = blog.PostCount;
            });
        }
コード例 #2
0
        public BlogPartHandler(IRepository <BlogPartRecord> repository, IWorkContextAccessor workContextAccessor, IEnumerable <IHomePageProvider> homePageProviders, IBlogPathConstraint blogPathConstraint)
        {
            _workContextAccessor      = workContextAccessor;
            _blogPathConstraint       = blogPathConstraint;
            _routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
            Filters.Add(StorageFilter.For(repository));

            Action <PublishContentContext, RoutePart> publishedHandler = (context, route) => {
                if (route.Is <BlogPart>())
                {
                    if (route.ContentItem.Id != 0 && route.PromoteToHomePage)
                    {
                        _blogPathConstraint.AddPath("");
                    }
                }
                else if (route.ContentItem.Id != 0 && route.PromoteToHomePage)
                {
                    _blogPathConstraint.RemovePath("");
                }
            };

            OnPublished <RoutePart>(publishedHandler);
            OnUnpublished <RoutePart>(publishedHandler);

            OnGetDisplayShape <BlogPart>((context, blog) => {
                context.Shape.Description = blog.Description;
                context.Shape.PostCount   = blog.PostCount;
            });
        }
コード例 #3
0
ファイル: BlogPartHandler.cs プロジェクト: sjbisch/Orchard
        public BlogPartHandler(IRepository<BlogPartRecord> repository, IBlogPathConstraint blogPathConstraint) {
            _blogPathConstraint = blogPathConstraint;
            Filters.Add(StorageFilter.For(repository));

            OnGetDisplayShape<BlogPart>((context, blog) => {
                context.Shape.Description = blog.Description;
                context.Shape.PostCount = blog.PostCount;
            });

            OnPublished<BlogPart>((context, blog) => _blogPathConstraint.AddPath(blog.As<IAliasAspect>().Path));
            OnUnpublished<BlogPart>((context, blog) => _blogPathConstraint.RemovePath(blog.As<IAliasAspect>().Path));
        }
コード例 #4
0
        public BlogPartHandler(IRepository <BlogPartRecord> repository, IBlogPathConstraint blogPathConstraint)
        {
            _blogPathConstraint = blogPathConstraint;
            Filters.Add(StorageFilter.For(repository));

            OnGetDisplayShape <BlogPart>((context, blog) => {
                context.Shape.Description = blog.Description;
                context.Shape.PostCount   = blog.PostCount;
            });

            OnPublished <BlogPart>((context, blog) => _blogPathConstraint.AddPath(blog.As <IAliasAspect>().Path));
            OnUnpublished <BlogPart>((context, blog) => _blogPathConstraint.RemovePath(blog.As <IAliasAspect>().Path));
        }
コード例 #5
0
        public ActionResult CreatePOST()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
            {
                return(new HttpUnauthorizedResult());
            }

            var blog = Services.ContentManager.New <BlogPart>("Blog");

            _contentManager.Create(blog, VersionOptions.Draft);
            dynamic model = _contentManager.UpdateEditor(blog, this);

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();
                // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
                return(View((object)model));
            }

            _contentManager.Publish(blog.ContentItem);
            _blogPathConstraint.AddPath(blog.As <IRoutableAspect>().Path);

            return(Redirect(Url.BlogForAdmin(blog)));
        }