/// <summary> /// Updates any Cache Objects that are associated with this entity /// </summary> /// <param name="entityState">State of the entity.</param> /// <param name="dbContext">The database context.</param> public void UpdateCache(EntityState entityState, Rock.Data.DbContext dbContext) { BlockCache.UpdateCachedEntity(this.Id, entityState); var model = this; if (model.SiteId.HasValue && model.SiteId != originalSiteId) { PageCache.FlushPagesForSite(model.SiteId.Value); } else if (model.LayoutId.HasValue && model.LayoutId != originalLayoutId) { PageCache.FlushPagesForLayout(model.LayoutId.Value); } if (originalSiteId.HasValue) { PageCache.FlushPagesForSite(originalSiteId.Value); } else if (originalLayoutId.HasValue) { PageCache.FlushPagesForLayout(originalLayoutId.Value); } else if (originalPageId.HasValue) { PageCache.FlushItem(originalPageId.Value); } }
/// <summary> /// Handles the SaveClick event of the mdAddBlock 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 mdAddBlock_SaveClick(object sender, EventArgs e) { using (var rockContext = new RockContext()) { BlockService blockService = new BlockService(rockContext); var page = PageCache.Get(hfPageId.Value.AsInteger()); Block block = new Rock.Model.Block(); block.Zone = ddlZones.SelectedValue; block.Name = tbNewBlockName.Text; block.BlockTypeId = ddlBlockType.SelectedValue.AsInteger(); if (rblAddBlockLocation.SelectedValue == "Site") { block.PageId = null; block.LayoutId = null; block.SiteId = page.SiteId; } else if (rblAddBlockLocation.SelectedValue == "Layout") { block.PageId = null; block.LayoutId = page.LayoutId; block.SiteId = null; } else if (rblAddBlockLocation.SelectedValue == "Page") { block.PageId = page.Id; block.LayoutId = null; block.SiteId = null; } block.Order = blockService.GetMaxOrder(block); blockService.Add(block); rockContext.SaveChanges(); Rock.Security.Authorization.CopyAuthorization(page, block, rockContext); if (block.LayoutId.HasValue) { PageCache.FlushPagesForLayout(page.LayoutId); } else { //page.RemoveBlocks(); PageCache.Remove(page.Id); } mdAddBlock.Hide(); ShowDetailForZone(ddlZones.SelectedValue); } }
/// <summary> /// Handles the GridReorder event of the gLayoutBlocks 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 gLayoutBlocks_GridReorder(object sender, GridReorderEventArgs e) { using (var rockContext = new RockContext()) { BlockService blockService = new BlockService(rockContext); var blocks = blockService.GetByLayoutAndZone(_Page.LayoutId, _ZoneName).ToList(); blockService.Reorder(blocks, e.OldIndex, e.NewIndex); rockContext.SaveChanges(); } PageCache.FlushPagesForLayout(_Page.LayoutId); PageUpdated = true; 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) { using (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(); PageCache.FlushPagesForLayout(_Page.LayoutId); PageUpdated = true; } } BindGrids(); }
private void SortPanelWidgets(string eventParam, string[] values) { string panelWidgetClientId = values[0]; int newIndex = int.Parse(values[1]); Panel pnlWidget = pnlDetails.ControlsOfTypeRecursive <Panel>().FirstOrDefault(a => a.ClientID == panelWidgetClientId); HiddenField hfSiteBlockId = pnlWidget.FindControl("hfSiteBlockId") as HiddenField; HiddenField hfLayoutBlockId = pnlWidget.FindControl("hfLayoutBlockId") as HiddenField; HiddenField hfPageBlockId = pnlWidget.FindControl("hfPageBlockId") as HiddenField; int?blockId = null; if (hfSiteBlockId != null) { blockId = hfSiteBlockId.Value.AsIntegerOrNull(); } else if (hfLayoutBlockId != null) { blockId = hfLayoutBlockId.Value.AsIntegerOrNull(); } else if (hfPageBlockId != null) { blockId = hfPageBlockId.Value.AsIntegerOrNull(); } if (blockId.HasValue) { var rockContext = new RockContext(); var blockService = new BlockService(rockContext); var block = blockService.Get(blockId.Value); var page = PageCache.Get(hfPageId.Value.AsInteger()); if (block != null && page != null) { List <Block> zoneBlocks = null; switch (block.BlockLocation) { case BlockLocation.Page: zoneBlocks = blockService.GetByPageAndZone(block.PageId.Value, block.Zone).ToList(); break; case BlockLocation.Layout: zoneBlocks = blockService.GetByLayoutAndZone(block.LayoutId.Value, block.Zone).ToList(); break; case BlockLocation.Site: zoneBlocks = blockService.GetBySiteAndZone(block.SiteId.Value, block.Zone).ToList(); break; } if (zoneBlocks != null) { var oldIndex = zoneBlocks.IndexOf(block); blockService.Reorder(zoneBlocks, oldIndex, newIndex); rockContext.SaveChanges(); } PageCache.Remove(page.Id); if (block.LayoutId.HasValue) { PageCache.FlushPagesForLayout(block.LayoutId.Value); } if (block.SiteId.HasValue) { PageCache.FlushPagesForSite(block.SiteId.Value); } ShowDetailForZone(ddlZones.SelectedValue); } } }
/// <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) { bool newBlock = false; Rock.Model.Block block = null; using (var rockContext = new RockContext()) { BlockService blockService = new BlockService(rockContext); int blockId = hfBlockId.ValueAsInt(); if (blockId != 0) { block = blockService.Get(blockId); } if (block == null) { newBlock = true; block = new Rock.Model.Block(); blockService.Add(block); BlockLocation location = hfBlockLocation.Value.ConvertToEnum <BlockLocation>(); switch (location) { case BlockLocation.Site: block.LayoutId = null; block.PageId = null; block.SiteId = _Page.SiteId; break; case BlockLocation.Layout: block.LayoutId = _Page.LayoutId; block.PageId = null; block.SiteId = null; break; case BlockLocation.Page: block.LayoutId = null; block.PageId = _Page.Id; block.SiteId = null; break; } block.Zone = _ZoneName; Rock.Model.Block lastBlock = blockService.GetByPageAndZone(_Page.Id, _ZoneName).OrderByDescending(b => b.Order).FirstOrDefault(); var maxOrder = blockService.GetMaxOrder(block); if (lastBlock != null) { block.Order = lastBlock.Order + 1; } else { block.Order = 0; } } block.Name = tbBlockName.Text; block.BlockTypeId = Convert.ToInt32(ddlBlockType.SelectedValue); rockContext.SaveChanges(); if (newBlock) { Rock.Security.Authorization.CopyAuthorization(_Page, block, rockContext); } if (block.Layout != null) { PageCache.FlushPagesForLayout(_Page.LayoutId); } else { //_Page.RemoveBlocks(); PageCache.Remove(_Page.Id); } } PageUpdated = true; BindGrids(); pnlDetails.Visible = false; pnlLists.Visible = true; }