protected void gLayoutBlocks_Delete(object sender, RowEventArgs e) { Rock.Model.Block block = blockService.Get(( int )gLayoutBlocks.DataKeys[e.RowIndex]["id"]); if (CurrentBlock != null) { blockService.Delete(block, CurrentPersonId); blockService.Save(block, CurrentPersonId); Rock.Web.Cache.PageCache.FlushLayoutBlocks(_page.Layout); } BindGrids(); }
public void Move( int id, Block block ) { var user = CurrentUser(); if ( user != null ) { var service = new BlockService(); block.Id = id; Block model; if ( !service.TryGet( id, out model ) ) throw new HttpResponseException( HttpStatusCode.NotFound ); if ( !model.IsAuthorized( "Edit", user.Person ) ) throw new HttpResponseException( HttpStatusCode.Unauthorized ); if ( model.LayoutId.HasValue && model.LayoutId != block.LayoutId ) Rock.Web.Cache.PageCache.FlushLayoutBlocks( model.LayoutId.Value ); if ( block.LayoutId.HasValue ) Rock.Web.Cache.PageCache.FlushLayoutBlocks( block.LayoutId.Value ); else { var page = Rock.Web.Cache.PageCache.Read( block.PageId.Value ); page.FlushBlocks(); } model.Zone = block.Zone; model.PageId = block.PageId; model.LayoutId = block.LayoutId; if ( model.IsValid ) { model.Order = service.GetMaxOrder( model ); service.Save( model, user.PersonId ); } else throw new HttpResponseException( HttpStatusCode.BadRequest ); } else throw new HttpResponseException( HttpStatusCode.Unauthorized ); }
/// <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 ); } }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); Rock.Model.Block block; BlockService blockService = new BlockService(); int blockId = hfBlockId.ValueAsInt(); if ( blockId == 0 ) { block = new Rock.Model.Block(); BlockLocation location = hfBlockLocation.Value.ConvertToEnum<BlockLocation>(); if ( location == BlockLocation.Layout ) { block.LayoutId = page.LayoutId; block.PageId = null; } else { block.LayoutId = null; block.PageId = page.Id; } block.Zone = zoneName; Rock.Model.Block lastBlock = blockService.GetByPageAndZone( page.Id, zoneName ).OrderByDescending( b => b.Order ).FirstOrDefault(); if ( lastBlock != null ) { block.Order = lastBlock.Order + 1; } else { block.Order = 0; } blockService.Add( block, CurrentPersonId ); } else { block = blockService.Get( blockId ); } block.Name = tbBlockName.Text; block.BlockTypeId = Convert.ToInt32( ddlBlockType.SelectedValue ); blockService.Save( block, CurrentPersonId ); Rock.Security.Authorization.CopyAuthorization( page, block, CurrentPersonId ); if ( block.Layout != null ) { Rock.Web.Cache.PageCache.FlushLayoutBlocks( page.LayoutId ); } else { page.FlushBlocks(); } BindGrids(); pnlDetails.Visible = false; pnlLists.Visible = true; }
/// <summary> /// Handles the Delete event of the gPageBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gPageBlocks_Delete( object sender, RowEventArgs e ) { BlockService blockService = new BlockService(); int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); Rock.Model.Block block = blockService.Get( e.RowKeyId ); if ( block != null ) { blockService.Delete( block, CurrentPersonId ); blockService.Save( block, CurrentPersonId ); page.FlushBlocks(); } BindGrids(); }
/// <summary> /// Handles the Delete event of the gLayoutBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gLayoutBlocks_Delete( object sender, RowEventArgs e ) { BlockService blockService = new BlockService(); int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); Rock.Model.Block block = blockService.Get( (int)gLayoutBlocks.DataKeys[e.RowIndex]["id"] ); if ( block != null ) { blockService.Delete( block, CurrentPersonId ); blockService.Save( block, CurrentPersonId ); Rock.Web.Cache.PageCache.FlushLayoutBlocks( page.LayoutId ); } BindGrids(); }