Пример #1
0
        public void SaveSiteContent(ref SiteContent content, int auditUserId)
        {
            // Ensure 0 values are set to null, otherwise we'll get FK errors
            if (content.SiteContentParentID <= 0)
            {
                content.SiteContentParentID = null;
            }

            // Clear Publish Date
            if (content.Status != ContentStatus.Published && content.PublishDateUtc.HasValue)
            {
                content.PublishDateUtc = null;
            }

            // Update audit fields
            if (content.SiteContentID <= 0)
            {
                content.SetAuditFields(auditUserId);
            }
            else
            {
                content.UpdateAuditFields(auditUserId);
            }

            // Ensure default content version
            if (content.IsContentPage() && content.Versions.IsNullOrEmpty())
            {
                var site = GetSite(new SiteRequest()
                {
                    SiteID = content.SiteID, IncludeSiteTemplates = true
                });
                var template = site.SiteTemplates.First();

                if (site.DefaultSiteTemplateID.HasValue)
                {
                    template = site.SiteTemplates.First(s => s.SiteTemplateID == site.DefaultSiteTemplateID);
                }

                content.Versions.Add(new SiteContentVersion()
                {
                    SiteContentID  = content.SiteContentID,
                    VersionName    = "Default",
                    SiteTemplateID = template.SiteTemplateID,
                    ContentText    = template.DefaultContent
                });
            }

            // Only content pages should have versions
            if (!content.IsContentPage() && !content.Versions.IsNullOrEmpty())
            {
                content.Versions.Clear();
            }

            // Ensure audit fields on versions
            foreach (var version in content.Versions.Where(version => version.SiteContentVersionID <= 0))
            {
                version.SetAuditFields(auditUserId);
            }

            // Save it
            _cmsRepository.SaveSiteContent(content);

            // Clear CMS-related cache
            _cacheStorage.ClearNamespace("Cms");
        }