Exemple #1
0
        protected void SavePage(bool bRedirect)
        {
            ContentPage pageContents = null;

            if (guidVersionContentID != Guid.Empty)
            {
                pageContents = pageHelper.GetVersion(SiteID, guidVersionContentID);
            }
            if (guidContentID != Guid.Empty && pageContents == null)
            {
                pageContents = pageHelper.FindContentByID(SiteID, guidContentID);
            }
            if (guidImportContentID != Guid.Empty)
            {
                pageContents = ContentImportExportUtils.GetSerializedContentPageExport(guidImportContentID).ThePage;

                if (pageContents != null)
                {
                    pageContents.SiteID       = SiteID;
                    pageContents.EditDate     = SiteData.CurrentSite.Now;
                    pageContents.CreateUserId = SecurityData.CurrentUserGuid;
                    pageContents.CreateDate   = SiteData.CurrentSite.Now;

                    var rp = pageHelper.GetLatestContentByURL(SiteID, false, pageContents.FileName);
                    if (rp != null)
                    {
                        pageContents.Root_ContentID = rp.Root_ContentID;
                        pageContents.ContentID      = rp.ContentID;
                    }
                    else
                    {
                        pageContents.Root_ContentID = Guid.Empty;
                        pageContents.ContentID      = Guid.Empty;
                    }
                    pageContents.Parent_ContentID = null;
                    pageContents.NavOrder         = SiteData.BlogSortOrderNumber;
                }
            }

            if (pageContents == null)
            {
                pageContents = new ContentPage(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry);
            }

            DateTime dtSite = CalcNearestFiveMinTime(SiteData.CurrentSite.Now);

            pageContents.GoLiveDate = dtSite.AddMinutes(-5);
            pageContents.RetireDate = dtSite.AddYears(200);

            pageContents.IsLatestVersion = true;
            pageContents.Thumbnail       = txtThumb.Text;

            pageContents.TemplateFile = ddlTemplate.SelectedValue;

            pageContents.TitleBar    = txtTitle.Text;
            pageContents.NavMenuText = txtNav.Text;
            pageContents.PageHead    = txtHead.Text;
            pageContents.PageSlug    = txtPageSlug.Text;

            pageContents.MetaDescription = txtDescription.Text;
            pageContents.MetaKeyword     = txtKey.Text;

            pageContents.EditDate = SiteData.CurrentSite.Now;
            pageContents.NavOrder = SiteData.BlogSortOrderNumber;

            pageContents.PageText      = reBody.Text;
            pageContents.LeftPageText  = reLeftBody.Text;
            pageContents.RightPageText = reRightBody.Text;

            pageContents.PageActive    = chkActive.Checked;
            pageContents.ShowInSiteNav = false;
            pageContents.ShowInSiteMap = false;
            pageContents.BlockIndex    = chkHide.Checked;

            pageContents.ContentType = ContentPageType.PageType.BlogEntry;

            pageContents.Parent_ContentID = null;

            if (String.IsNullOrEmpty(hdnCreditUserID.Value))
            {
                pageContents.CreditUserId = null;
            }
            else
            {
                var usr = new ExtendedUserData(hdnCreditUserID.Value);
                pageContents.CreditUserId = usr.UserId;
            }

            pageContents.GoLiveDate = Convert.ToDateTime(txtReleaseDate.Text + " " + txtReleaseTime.Text);
            pageContents.RetireDate = Convert.ToDateTime(txtRetireDate.Text + " " + txtRetireTime.Text);
            pageContents.EditUserId = SecurityData.CurrentUserGuid;

            pageContents.NewTrackBackURLs = txtTrackback.Text;

            List <ContentCategory> lstCat = new List <ContentCategory>();
            List <ContentTag>      lstTag = new List <ContentTag>();

            lstCat = (from cr in GeneralUtilities.GetSelectedValues(listCats).Select(x => new Guid(x))
                      join l in SiteData.CurrentSite.GetCategoryList() on cr equals l.ContentCategoryID
                      select l).ToList();

            lstTag = (from cr in GeneralUtilities.GetSelectedValues(listTags).Select(x => new Guid(x))
                      join l in SiteData.CurrentSite.GetTagList() on cr equals l.ContentTagID
                      select l).ToList();

            pageContents.ContentCategories = lstCat;
            pageContents.ContentTags       = lstTag;

            if (!chkDraft.Checked)
            {
                pageContents.SavePageEdit();
            }
            else
            {
                pageContents.SavePageAsDraft();
            }

            //if importing, copy in all meta data possible
            if (guidImportContentID != Guid.Empty)
            {
                List <Widget> widgets = ContentImportExportUtils.GetSerializedContentPageExport(guidImportContentID).ThePageWidgets;

                foreach (var wd in widgets)
                {
                    wd.Root_ContentID  = pageContents.Root_ContentID;
                    wd.Root_WidgetID   = Guid.NewGuid();
                    wd.WidgetDataID    = Guid.NewGuid();
                    wd.IsPendingChange = true;
                    wd.EditDate        = SiteData.CurrentSite.Now;
                    wd.Save();
                }

                ContentImportExportUtils.RemoveSerializedExportData(guidImportContentID);
            }

            cmsHelper.OverrideKey(pageContents.Root_ContentID);
            if (cmsHelper.cmsAdminWidget != null)
            {
                var ww = (from w in cmsHelper.cmsAdminWidget
                          where w.IsLatestVersion == true &&
                          w.IsPendingChange == true &&
                          (w.ControlPath.StartsWith("CLASS:Carrotware.CMS.UI.Controls.ContentRichText,") ||
                           w.ControlPath.StartsWith("CLASS:Carrotware.CMS.UI.Controls.ContentPlainText,"))
                          select w);

                foreach (Widget w in ww)
                {
                    w.Save();
                }
            }

            cmsHelper.cmsAdminContent = null;
            cmsHelper.cmsAdminWidget  = null;

            if (pageContents.FileName.ToLower().EndsWith(SiteData.DefaultDirectoryFilename))
            {
                VirtualDirectory.RegisterRoutes(true);
            }

            if (!bRedirect)
            {
                if (sPageMode.Length < 1)
                {
                    Response.Redirect(SiteData.CurrentScriptName + "?id=" + pageContents.Root_ContentID.ToString());
                }
                else
                {
                    Response.Redirect(SiteData.CurrentScriptName + "?mode=raw&id=" + pageContents.Root_ContentID.ToString());
                }
            }
            else
            {
                Response.Redirect(pageContents.FileName);
            }
        }