/// <summary>
        /// Flushes the block type attributes.
        /// </summary>
        private void FlushBlockTypeAttributes()
        {
            // Flush BlockType, Block and Entity Attributes
            AttributeCache.FlushEntityAttributes();

            BlockTypeCache.Flush(hfBlockTypeId.Value.AsInteger());
            var blockTypeCache = BlockTypeCache.Read(hfBlockTypeId.Value.AsInteger());

            foreach (var blockId in new BlockService(new RockContext()).GetByBlockTypeId(hfBlockTypeId.Value.AsInteger()).Select(a => a.Id).ToList())
            {
                BlockCache.Flush(blockId);
            }
        }
示例#2
0
        /// <summary>
        /// Handles the Delete click event for the grid.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteBlock_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);
            Block        block        = blockService.Get(e.RowKeyId);

            if (block != null)
            {
                string errorMessage;
                if (!blockService.CanDelete(block, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                blockService.Delete(block);
                rockContext.SaveChanges();

                BlockCache.Flush(e.RowKeyId);
            }

            BindLayoutBlocksGrid();
        }
示例#3
0
        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         = Rock.Web.Cache.PageCache.Read(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();
                    }

                    foreach (var zoneBlock in zoneBlocks)
                    {
                        // make sure the BlockCache for all the re-ordered blocks get flushed so the new Order is updated
                        BlockCache.Flush(zoneBlock.Id);
                    }

                    page.FlushBlocks();
                    if (block.LayoutId.HasValue)
                    {
                        Rock.Web.Cache.PageCache.FlushLayoutBlocks(block.LayoutId.Value);
                    }

                    if (block.SiteId.HasValue)
                    {
                        Rock.Web.Cache.PageCache.FlushSiteBlocks(block.SiteId.Value);
                    }

                    ShowDetailForZone(ddlZones.SelectedValue);
                }
            }
        }