/// <summary> /// Recursively saves Pages and associated Blocks, PageRoutes and PageContexts. /// </summary> /// <param name="page">The current Page to save</param> /// <param name="newBlockTypes">List of BlockTypes not currently installed</param> /// <param name="personId">Id of the Person performing the "Import" operation</param> /// <param name="parentPageId">Id of the the current Page's parent</param> /// <param name="siteId">Id of the site the current Page is being imported into</param> private void SavePages( Page page, IEnumerable<BlockType> newBlockTypes, int personId, int parentPageId, int siteId ) { // find layout var layoutService = new LayoutService(); var layout = layoutService.GetBySiteId(siteId).Where( l => l.Name == page.Layout.Name && l.FileName == page.Layout.FileName ).FirstOrDefault(); if ( layout == null ) { layout = new Layout(); layout.FileName = page.Layout.FileName; layout.Name = page.Layout.Name; layout.SiteId = siteId; layoutService.Add( layout, null ); layoutService.Save( layout, null ); } int layoutId = layout.Id; // Force shallow copies on entities so save operations are more atomic and don't get hosed // by nested object references. var pg = page.Clone(deepCopy: false); var blockTypes = newBlockTypes.ToList(); pg.ParentPageId = parentPageId; pg.LayoutId = layoutId; var pageService = new PageService(); pageService.Add( pg, personId ); pageService.Save( pg, personId ); var blockService = new BlockService(); foreach ( var block in page.Blocks ?? new List<Block>() ) { var blockType = blockTypes.FirstOrDefault( bt => block.BlockType.Path == bt.Path ); var b = block.Clone( deepCopy: false ); b.PageId = pg.Id; if ( blockType != null ) { b.BlockTypeId = blockType.Id; } blockService.Add( b, personId ); blockService.Save( b, personId ); } var pageRouteService = new PageRouteService(); foreach ( var pageRoute in page.PageRoutes ?? new List<PageRoute>() ) { var pr = pageRoute.Clone(deepCopy: false); pr.PageId = pg.Id; pageRouteService.Add( pr, personId ); pageRouteService.Save( pr, personId ); } var pageContextService = new PageContextService(); foreach ( var pageContext in page.PageContexts ?? new List<PageContext>() ) { var pc = pageContext.Clone(deepCopy: false); pc.PageId = pg.Id; pageContextService.Add( pc, personId ); pageContextService.Save( pc, personId ); } foreach ( var p in page.Pages ?? new List<Page>() ) { SavePages( p, blockTypes, personId, pg.Id, siteId ); } }
protected void lbSave_Click( object sender, EventArgs e ) { if ( updatePage ) { var pageCache = PageCache.Read( RockPage.PageId ); if ( pageCache != null && ( pageCache.PageTitle != tbName.Text || pageCache.Description != tbDesc.Text ) ) { var service = new PageService(); var page = service.Get( pageCache.Id ); page.InternalName = tbName.Text; page.PageTitle = tbName.Text; page.BrowserTitle = tbName.Text; page.Description = tbDesc.Text; service.Save( page, CurrentPersonId ); Rock.Web.Cache.PageCache.Flush( page.Id ); pageCache = PageCache.Read( RockPage.PageId ); var breadCrumb = RockPage.BreadCrumbs.Where( c => c.Url == RockPage.PageReference.BuildUrl() ).FirstOrDefault(); if (breadCrumb != null) { breadCrumb.Name = pageCache.BreadCrumbText; } } } SetAttributeValue( "Query", ceQuery.Text ); SetAttributeValue( "QueryParams", tbParams.Text ); SetAttributeValue( "UrlMask", tbUrlMask.Text ); SetAttributeValue( "Columns", tbColumns.Text ); SetAttributeValue( "ShowColumns", ddlHideShow.SelectedValue ); SetAttributeValue( "FormattedOutput", ceFormattedOutput.Text ); SetAttributeValue( "PersonReport", cbPersonReport.Checked.ToString()); SetAttributeValue( "MergeFields", tbMergeFields.Text ); SaveAttributeValues( CurrentPersonId ); BindGrid(); }
protected void rGrid_Delete( object sender, RowEventArgs e ) { using ( new UnitOfWorkScope() ) { var pageService = new PageService(); var siteService = new SiteService(); var page = pageService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] ); if ( page != null ) { RockTransactionScope.WrapTransaction( () => { foreach ( var site in siteService.Queryable() ) { bool updateSite = false; if (site.DefaultPageId == page.Id) { site.DefaultPageId = null; site.DefaultPageRouteId = null; updateSite = true; } if (site.LoginPageId == page.Id) { site.LoginPageId = null; site.LoginPageRouteId = null; updateSite = true; } if (site.RegistrationPageId == page.Id) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; updateSite = true; } if (updateSite) { siteService.Save( site, CurrentPersonId ); } } pageService.Delete( page, CurrentPersonId ); pageService.Save( page, CurrentPersonId ); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) _page.FlushChildPages(); } ); } } BindGrid(); }
protected void lbSave_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { Rock.Model.Page page; var pageService = new PageService(); int pageId = 0; if ( !Int32.TryParse( hfPageId.Value, out pageId ) ) pageId = 0; if ( pageId == 0 ) { page = new Rock.Model.Page(); if ( _page != null ) { page.ParentPageId = _page.Id; page.LayoutId = _page.LayoutId; } else { page.ParentPageId = null; page.LayoutId = PageCache.Read( RockPage.PageId ).LayoutId; } page.PageTitle = dtbPageName.Text; page.BrowserTitle = page.PageTitle; page.EnableViewState = true; page.IncludeAdminFooter = true; Rock.Model.Page lastPage = pageService.GetByParentPageId( _page.Id ). OrderByDescending( b => b.Order ).FirstOrDefault(); if ( lastPage != null ) page.Order = lastPage.Order + 1; else page.Order = 0; pageService.Add( page, CurrentPersonId ); } else page = pageService.Get( pageId ); page.LayoutId = ddlLayout.SelectedValueAsInt().Value; page.InternalName = dtbPageName.Text; if ( page.IsValid ) { pageService.Save( page, CurrentPersonId ); if ( _page != null ) { Rock.Security.Authorization.CopyAuthorization( _page, page, CurrentPersonId ); _page.FlushChildPages(); } BindGrid(); } rGrid.Visible = true; pnlDetails.Visible = false; } }
/// <summary> /// Handles the OnSave event of the masterPage control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void masterPage_OnSave( object sender, EventArgs e ) { Page.Validate( BlockValidationGroup ); if ( Page.IsValid ) { using ( new UnitOfWorkScope() ) { var pageService = new PageService(); var routeService = new PageRouteService(); var contextService = new PageContextService(); var page = pageService.Get( _page.Id ); int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0; if ( page.ParentPageId != parentPageId ) { if ( page.ParentPageId.HasValue ) { PageCache.Flush( page.ParentPageId.Value ); } if ( parentPageId != 0 ) { PageCache.Flush( parentPageId ); } } page.InternalName = tbPageName.Text; page.PageTitle = tbPageTitle.Text; page.BrowserTitle = tbBrowserTitle.Text; if ( parentPageId != 0 ) { page.ParentPageId = parentPageId; } else { page.ParentPageId = null; } page.LayoutId = ddlLayout.SelectedValueAsInt().Value; int? orphanedIconFileId = null; page.IconCssClass = tbIconCssClass.Text; page.PageDisplayTitle = cbPageTitle.Checked; page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked; page.PageDisplayIcon = cbPageIcon.Checked; page.PageDisplayDescription = cbPageDescription.Checked; page.DisplayInNavWhen = (DisplayInNavWhen)Enum.Parse( typeof( DisplayInNavWhen ), ddlMenuWhen.SelectedValue ); page.MenuDisplayDescription = cbMenuDescription.Checked; page.MenuDisplayIcon = cbMenuIcon.Checked; page.MenuDisplayChildPages = cbMenuChildPages.Checked; page.BreadCrumbDisplayName = cbBreadCrumbName.Checked; page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked; page.RequiresEncryption = cbRequiresEncryption.Checked; page.EnableViewState = cbEnableViewState.Checked; page.IncludeAdminFooter = cbIncludeAdminFooter.Checked; page.OutputCacheDuration = int.Parse( tbCacheDuration.Text ); page.Description = tbDescription.Text; page.HeaderContent = ceHeaderContent.Text; // new or updated route foreach ( var pageRoute in page.PageRoutes.ToList() ) { var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id ); if ( existingRoute != null ) { RouteTable.Routes.Remove( existingRoute ); } routeService.Delete( pageRoute, CurrentPersonId ); } page.PageRoutes.Clear(); foreach ( string route in tbPageRoute.Text.SplitDelimitedValues() ) { var pageRoute = new PageRoute(); pageRoute.Route = route; pageRoute.Guid = Guid.NewGuid(); page.PageRoutes.Add( pageRoute ); } foreach ( var pageContext in page.PageContexts.ToList() ) { contextService.Delete( pageContext, CurrentPersonId ); } page.PageContexts.Clear(); foreach ( var control in phContext.Controls ) { if ( control is RockTextBox ) { var tbContext = control as RockTextBox; if ( !string.IsNullOrWhiteSpace( tbContext.Text ) ) { var pageContext = new PageContext(); pageContext.Entity = tbContext.ID.Substring(8).Replace('_', '.'); pageContext.IdParameter = tbContext.Text; page.PageContexts.Add( pageContext ); } } } if ( page.IsValid ) { pageService.Save( page, CurrentPersonId ); foreach ( var pageRoute in new PageRouteService().GetByPageId( page.Id ) ) { RouteTable.Routes.AddPageRoute( pageRoute ); } Rock.Attribute.Helper.GetEditValues( phAttributes, _page ); _page.SaveAttributeValues( CurrentPersonId ); if ( orphanedIconFileId.HasValue) { BinaryFileService binaryFileService = new BinaryFileService(); var binaryFile = binaryFileService.Get( orphanedIconFileId.Value ); if ( binaryFile != null ) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; binaryFileService.Save( binaryFile, CurrentPersonId ); } } Rock.Web.Cache.PageCache.Flush( _page.Id ); string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');"; ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true ); } } } }