/// <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 GridReorder event of the gSiteBlocks 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 gSiteBlocks_GridReorder(object sender, GridReorderEventArgs e) { using (var rockContext = new RockContext()) { BlockService blockService = new BlockService(rockContext); var blocks = blockService.GetBySiteAndZone(_Page.SiteId, _ZoneName).ToList(); blockService.Reorder(blocks, e.OldIndex, e.NewIndex); rockContext.SaveChanges(); } PageCache.FlushPagesForSite(_Page.SiteId); PageUpdated = true; BindGrids(); }
/// <summary> /// Handles the Delete event of the gSiteBlocks 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 gSiteBlocks_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.FlushPagesForSite(_Page.SiteId); 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); } } }