コード例 #1
0
        /// <summary>
        /// Saves SEO information.
        /// </summary>
        /// <param name="model">The SEO information model.</param>
        /// <returns>
        /// true if SEO information saved successfully; false otherwise.
        /// </returns>
        public virtual EditSeoViewModel Execute(EditSeoViewModel model)
        {
            var page = Repository.First <PageProperties>(model.PageId);

            bool initialHasSeo = page.HasSEO;

            Models.Redirect newRedirect = null;

            page.Version = model.Version;
            page.Title   = model.PageTitle;

            model.ChangedUrlPath = urlService.FixUrl(model.ChangedUrlPath);

            if (!string.Equals(model.PageUrlPath, model.ChangedUrlPath))
            {
                pageService.ValidatePageUrl(model.ChangedUrlPath, model.PageId);

                if (model.CreatePermanentRedirect)
                {
                    var redirect = redirectService.CreateRedirectEntity(model.PageUrlPath, model.ChangedUrlPath);
                    if (redirect != null)
                    {
                        Repository.Save(redirect);
                        newRedirect = redirect;
                    }
                }

                page.NodeCountInSitemap = model.UpdateSitemap
                    ? sitemapService.ChangeUrl(page.PageUrl, model.ChangedUrlPath)
                    : sitemapService.NodesWithUrl(model.ChangedUrlPath);

                page.PageUrl = model.ChangedUrlPath;
            }

            page.PageUrlHash     = page.PageUrl.UrlHash();
            page.MetaTitle       = model.MetaTitle;
            page.MetaKeywords    = model.MetaKeywords;
            page.MetaDescription = model.MetaDescription;
            page.UseCanonicalUrl = model.UseCanonicalUrl;

            Repository.Save(page);
            UnitOfWork.Commit();

            // Notify about SEO change.
            if (page.HasSEO != initialHasSeo)
            {
                Events.PageEvents.Instance.OnPageSeoStatusChanged(page);
            }

            // Notify about new redirect creation.
            if (newRedirect != null)
            {
                Events.PageEvents.Instance.OnRedirectCreated(newRedirect);
            }

            return(new EditSeoViewModel {
                PageUrlPath = page.PageUrl
            });
        }
コード例 #2
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Save response.</returns>
        /// <exception cref="CmsException">Failed to save page properties.</exception>
        public SavePageResponse Execute(EditPagePropertiesViewModel request)
        {
            UnitOfWork.BeginTransaction();

            var pageQuery = Repository
                            .AsQueryable <PageProperties>(p => p.Id == request.Id)
                            .FetchMany(p => p.Options)
                            .Fetch(p => p.Layout).ThenFetchMany(l => l.LayoutOptions)
                            .AsQueryable();

            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                pageQuery = pageQuery.FetchMany(f => f.AccessRules);
            }

            var page = pageQuery.ToList().FirstOne();

            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                AccessControlService.DemandAccess(page, Context.Principal, AccessLevel.ReadWrite, RootModuleConstants.UserRoles.EditContent, RootModuleConstants.UserRoles.PublishContent);
            }
            else
            {
                AccessControlService.DemandAccess(Context.Principal, RootModuleConstants.UserRoles.EditContent, RootModuleConstants.UserRoles.PublishContent);
            }

            Models.Redirect redirectCreated  = null;
            bool            initialSeoStatus = page.HasSEO;

            request.PageUrl = urlService.FixUrl(request.PageUrl);

            if (!string.Equals(page.PageUrl, request.PageUrl))
            {
                pageService.ValidatePageUrl(request.PageUrl, request.Id);
                if (request.RedirectFromOldUrl)
                {
                    var redirect = redirectService.CreateRedirectEntity(page.PageUrl, request.PageUrl);
                    if (redirect != null)
                    {
                        Repository.Save(redirect);
                        redirectCreated = redirect;
                    }
                }

                page.NodeCountInSitemap = request.UpdateSitemap
                    ? sitemapService.ChangeUrl(page.PageUrl, request.PageUrl)
                    : sitemapService.NodesWithUrl(request.PageUrl);

                page.PageUrl = request.PageUrl;
            }

            page.PageUrlHash = page.PageUrl.UrlHash();
            page.Layout      = Repository.AsProxy <Root.Models.Layout>(request.TemplateId);
            page.Category    = request.CategoryId.HasValue ? Repository.AsProxy <CategoryEntity>(request.CategoryId.Value) : null;
            page.Title       = request.PageName;
            page.CustomCss   = request.PageCSS;
            page.CustomJS    = request.PageJavascript;

            var publishDraftContent = false;

            if (request.CanPublishPage)
            {
                AccessControlService.DemandAccess(Context.Principal, RootModuleConstants.UserRoles.PublishContent);

                if (request.IsPagePublished)
                {
                    if (page.Status != PageStatus.Published)
                    {
                        page.Status         = PageStatus.Published;
                        page.PublishedOn    = DateTime.Now;
                        publishDraftContent = true;
                    }
                }
                else
                {
                    page.Status = PageStatus.Unpublished;
                }
            }

            page.UseNoFollow     = request.UseNoFollow;
            page.UseNoIndex      = request.UseNoIndex;
            page.UseCanonicalUrl = request.UseCanonicalUrl;
            page.IsArchived      = request.IsArchived;
            page.Version         = request.Version;

            page.Image          = request.Image != null && request.Image.ImageId.HasValue ? Repository.AsProxy <MediaImage>(request.Image.ImageId.Value) : null;
            page.SecondaryImage = request.SecondaryImage != null && request.SecondaryImage.ImageId.HasValue ? Repository.AsProxy <MediaImage>(request.SecondaryImage.ImageId.Value) : null;
            page.FeaturedImage  = request.FeaturedImage != null && request.FeaturedImage.ImageId.HasValue ? Repository.AsProxy <MediaImage>(request.FeaturedImage.ImageId.Value) : null;

            var optionValues  = page.Options.Distinct();
            var parentOptions = page.Layout.LayoutOptions.Distinct();

            optionService.SaveOptionValues(request.OptionValues, optionValues, parentOptions, () => new PageOption {
                Page = page
            });

            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                page.AccessRules.RemoveDuplicateEntities();

                var accessRules = request.UserAccessList != null?request.UserAccessList.Cast <IAccessRule>().ToList() : null;

                accessControlService.UpdateAccessControl(page, accessRules);
            }

            Repository.Save(page);

            // Save tags
            IList <Tag> newTags;

            tagService.SavePageTags(page, request.Tags, out newTags);

            if (publishDraftContent)
            {
                contentService.PublishDraftContent(page.Id);
            }

            UnitOfWork.Commit();

            // Notify about page properties change.
            Events.PageEvents.Instance.OnPagePropertiesChanged(page);

            // Notify about redirect creation.
            if (redirectCreated != null)
            {
                Events.PageEvents.Instance.OnRedirectCreated(redirectCreated);
            }

            // Notify about SEO status change.
            if (initialSeoStatus != page.HasSEO)
            {
                Events.PageEvents.Instance.OnPageSeoStatusChanged(page);
            }

            // Notify about new tags.
            Events.RootEvents.Instance.OnTagCreated(newTags);

            return(new SavePageResponse(page));
        }
コード例 #3
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Save response.</returns>
        /// <exception cref="CmsException">Failed to save page properties.</exception>
        public SavePageResponse Execute(EditPagePropertiesViewModel request)
        {
            UnitOfWork.BeginTransaction();

            var page = Repository
                       .AsQueryable <PageProperties>(p => p.Id == request.Id)
                       .FetchMany(p => p.Options)
                       .Fetch(p => p.Layout).ThenFetchMany(l => l.LayoutOptions)
                       .ToList()
                       .FirstOrDefault();

            Models.Redirect redirectCreated  = null;
            bool            initialSeoStatus = page.HasSEO;

            request.PageUrl = urlService.FixUrl(request.PageUrl);

            if (!string.Equals(page.PageUrl, request.PageUrl))
            {
                pageService.ValidatePageUrl(request.PageUrl, request.Id);
                if (request.RedirectFromOldUrl)
                {
                    var redirect = redirectService.CreateRedirectEntity(page.PageUrl, request.PageUrl);
                    if (redirect != null)
                    {
                        Repository.Save(redirect);
                        redirectCreated = redirect;
                    }
                }

                page.NodeCountInSitemap = request.UpdateSitemap
                    ? sitemapService.ChangeUrl(page.PageUrl, request.PageUrl)
                    : sitemapService.NodesWithUrl(request.PageUrl);

                page.PageUrl = request.PageUrl;
            }

            page.PageUrlLowerTrimmed = page.PageUrl.LowerTrimmedUrl();
            page.Layout    = Repository.AsProxy <Root.Models.Layout>(request.TemplateId);
            page.Category  = request.CategoryId.HasValue ? Repository.AsProxy <CategoryEntity>(request.CategoryId.Value) : null;
            page.Title     = request.PageName;
            page.CustomCss = request.PageCSS;
            page.CustomJS  = request.PageJavascript;

            if (request.IsVisibleToEveryone)
            {
                page.Status      = PageStatus.Published;
                page.PublishedOn = DateTime.Now;
            }
            else
            {
                page.Status = PageStatus.Unpublished;
            }

            page.UseNoFollow     = request.UseNoFollow;
            page.UseNoIndex      = request.UseNoIndex;
            page.UseCanonicalUrl = request.UseCanonicalUrl;
            page.IsArchived      = request.IsArchived;
            page.Version         = request.Version;

            page.Image          = request.Image != null && request.Image.ImageId.HasValue ? Repository.AsProxy <MediaImage>(request.Image.ImageId.Value) : null;
            page.SecondaryImage = request.SecondaryImage != null && request.SecondaryImage.ImageId.HasValue ? Repository.AsProxy <MediaImage>(request.SecondaryImage.ImageId.Value) : null;
            page.FeaturedImage  = request.FeaturedImage != null && request.FeaturedImage.ImageId.HasValue ? Repository.AsProxy <MediaImage>(request.FeaturedImage.ImageId.Value) : null;

            var optionValues  = page.Options.Distinct();
            var parentOptions = page.Layout.LayoutOptions.Distinct();

            optionService.SaveOptionValues(request.OptionValues, optionValues, parentOptions, () => new Root.Models.PageOption {
                Page = page
            });

            if (cmsConfiguration.AccessControlEnabled)
            {
                accessControlService.UpdateAccessControl(request.UserAccessList, request.Id);
            }

            Repository.Save(page);

            // Save tags
            IList <Root.Models.Tag> newTags;

            tagService.SavePageTags(page, request.Tags, out newTags);

            UnitOfWork.Commit();

            // Notify about page properties change.
            Events.PageEvents.Instance.OnPagePropertiesChanged(page);

            // Notify about redirect creation.
            if (redirectCreated != null)
            {
                Events.PageEvents.Instance.OnRedirectCreated(redirectCreated);
            }

            // Notify about SEO status change.
            if (initialSeoStatus != page.HasSEO)
            {
                Events.PageEvents.Instance.OnPageSeoStatusChanged(page);
            }

            // Notify about new tags.
            Events.RootEvents.Instance.OnTagCreated(newTags);

            return(new SavePageResponse(page));
        }
コード例 #4
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Save response.</returns>
        /// <exception cref="CmsException">Failed to save page properties.</exception>
        public SavePageResponse Execute(EditPagePropertiesViewModel request)
        {
            UnitOfWork.BeginTransaction();

            var page = Repository.First <PageProperties>(request.Id);

            Models.Redirect redirectCreated  = null;
            bool            initialSeoStatus = page.HasSEO;

            request.PageUrl = urlService.FixUrl(request.PageUrl);

            if (!string.Equals(page.PageUrl, request.PageUrl, StringComparison.OrdinalIgnoreCase))
            {
                pageService.ValidatePageUrl(request.PageUrl, request.Id);
                if (request.RedirectFromOldUrl)
                {
                    var redirect = redirectService.CreateRedirectEntity(page.PageUrl, request.PageUrl);
                    if (redirect != null)
                    {
                        Repository.Save(redirect);
                        redirectCreated = redirect;
                    }
                }

                page.NodeCountInSitemap = request.UpdateSitemap
                    ? sitemapService.ChangeUrl(page.PageUrl, request.PageUrl)
                    : sitemapService.NodesWithUrl(request.PageUrl);

                page.PageUrl = request.PageUrl;
            }

            page.Layout      = Repository.AsProxy <Root.Models.Layout>(request.TemplateId);
            page.Category    = request.CategoryId.HasValue ? Repository.AsProxy <Category>(request.CategoryId.Value) : null;
            page.Title       = request.PageName;
            page.CustomCss   = request.PageCSS;
            page.CustomJS    = request.PageJavascript;
            page.IsPublic    = request.IsVisibleToEveryone;
            page.UseNoFollow = request.UseNoFollow;
            page.UseNoIndex  = request.UseNoIndex;
            page.Version     = request.Version;

            if (request.Image != null && request.Image.ImageId.HasValue)
            {
                page.Image = Repository.AsProxy <MediaImage>(request.Image.ImageId.Value);
            }
            else
            {
                page.Image = null;
            }

            Repository.Save(page);

            // Save tags
            IList <Root.Models.Tag> newTags;

            tagService.SavePageTags(page, request.Tags, out newTags);

            UnitOfWork.Commit();

            // Notify about page properties change.
            PagesApiContext.Events.OnPagePropertiesChanged(page);

            // Notify about redirect creation.
            if (redirectCreated != null)
            {
                PagesApiContext.Events.OnRedirectCreated(redirectCreated);
            }

            // Notify about SEO status change.
            if (initialSeoStatus != page.HasSEO)
            {
                PagesApiContext.Events.OnPageSeoStatusChanged(page);
            }

            // Notify about new tags.
            PagesApiContext.Events.OnTagCreated(newTags);

            return(new SavePageResponse(page));
        }