protected void gPageBlocks_Delete(object sender, RowEventArgs e) { Rock.Model.Block block = blockService.Get(( int )gPageBlocks.DataKeys[e.RowIndex]["id"]); if (CurrentBlock != null) { blockService.Delete(block, CurrentPersonId); blockService.Save(block, CurrentPersonId); _page.FlushBlocks(); } BindGrids(); }
/// <summary> /// Handles the GridReorder event of the gPageBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param> protected void gPageBlocks_GridReorder(object sender, GridReorderEventArgs e) { using (var rockContext = new RockContext()) { BlockService blockService = new BlockService(rockContext); var blocks = blockService.GetByPageAndZone(_Page.Id, _ZoneName).ToList(); blockService.Reorder(blocks, e.OldIndex, e.NewIndex); rockContext.SaveChanges(); } _Page.FlushBlocks(); PageUpdated = true; BindGrids(); }
/// <summary> /// Handles the GridReorder event of the gPageBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param> protected void gPageBlocks_GridReorder(object sender, GridReorderEventArgs e) { int pageId = PageParameter("EditPage").AsInteger(); Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId); string zoneName = this.PageParameter("ZoneName"); var rockContext = new RockContext(); BlockService blockService = new BlockService(rockContext); var blocks = blockService.GetByPageAndZone(page.Id, zoneName).ToList(); blockService.Reorder(blocks, e.OldIndex, e.NewIndex); rockContext.SaveChanges(); page.FlushBlocks(); PageUpdated = true; BindGrids(); }
/// <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 (CurrentBlock != null) { blockService.Delete(block, CurrentPersonId); blockService.Save(block, CurrentPersonId); page.FlushBlocks(); } BindGrids(); }
/// <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) { int pageId = PageParameter("EditPage").AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId); string zoneName = this.PageParameter("ZoneName"); var rockContext = new RockContext(); BlockService blockService = new BlockService(rockContext); Rock.Model.Block block = blockService.Get(e.RowKeyId); if (block != null) { blockService.Delete(block); rockContext.SaveChanges(); page.FlushBlocks(); } BindGrids(); }
/// <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; var rockContext = new RockContext(); BlockService blockService = new BlockService(rockContext); 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); } else { block = blockService.Get(blockId); } block.Name = tbBlockName.Text; block.BlockTypeId = Convert.ToInt32(ddlBlockType.SelectedValue); rockContext.SaveChanges(); Rock.Security.Authorization.CopyAuthorization(page, block); if (block.Layout != null) { Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.LayoutId); } else { page.FlushBlocks(); } BindGrids(); pnlDetails.Visible = false; pnlLists.Visible = true; }