Example #1
0
        protected void btnSave_Click( object sender, EventArgs e )
        {
            Rock.Model.Block block;

            int blockId = 0;
            if ( !Int32.TryParse( hfBlockId.Value, out blockId ) )
                blockId = 0;

            if ( blockId == 0 )
            {
                block = new Rock.Model.Block();

                BlockLocation location = hfBlockLocation.Value.ConvertToEnum<BlockLocation>();
                if ( location == BlockLocation.Layout )
                {
                    block.Layout = _page.Layout;
                    block.PageId = null;
                }
                else
                {
                    block.Layout = null;
                    block.PageId = _page.Id;
                }

                block.Zone = _zoneName;

                Rock.Model.Block lastBlock =
                    blockService.GetByLayoutAndPageIdAndZone( null, _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.Layout);
            else
                _page.FlushBlocks();

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible = true;
        }
Example #2
0
        /// <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);
            }
        }
Example #3
0
        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();
        }
Example #4
0
        /// <summary>
        /// Flushes a block and it's parent page from cache whenever it is being deleted
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.ModelUpdatingEventArgs"/> instance containing the event data.</param>
        void Block_Deleting(object sender, Rock.Data.ModelUpdatingEventArgs e)
        {
            // Get a reference to the deleted block instance
            Rock.Model.Block block = e.Model as Rock.Model.Block;
            if (block != null)
            {
                // Flush the block instance from cache
                Rock.Web.Cache.BlockCache.Flush(block.Id);

                // Flush the block instance's parent page
                if (block.PageId.HasValue)
                {
                    Rock.Web.Cache.PageCache.Flush(block.PageId.Value);
                }
            }
        }
Example #5
0
        /// <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 (CurrentBlock != null)
            {
                blockService.Delete(block, CurrentPersonId);
                blockService.Save(block, CurrentPersonId);
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.Layout);
            }

            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)
        {
            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();

                    _Page.FlushBlocks();
                    PageUpdated = true;
                }
            }

            BindGrids();
        }
Example #7
0
        /// <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();
        }
Example #8
0
        /// <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)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);

            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);

            Rock.Model.Block block = blockService.Get((int)gLayoutBlocks.DataKeys[e.RowIndex]["id"]);
            if (block != null)
            {
                blockService.Delete(block);
                rockContext.SaveChanges();
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.LayoutId);
            }

            BindGrids();
        }
Example #9
0
        /// <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>
        /// Shows the edit.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="blockId">The block id.</param>
        protected void ShowEdit(BlockLocation location, int blockId)
        {
            using (var rockContext = new RockContext())
            {
                BlockService     blockService = new BlockService(rockContext);
                Rock.Model.Block block        = blockService.Get(blockId);
                hfBlockLocation.Value = location.ConvertToString();

                if (block != null)
                {
                    lAction.Text               = "Edit ";
                    hfBlockId.Value            = block.Id.ToString();
                    ddlBlockType.SelectedValue = block.BlockType.Id.ToString();
                    tbBlockName.Text           = block.Name;
                }
                else
                {
                    lAction.Text    = "Add ";
                    hfBlockId.Value = "0";

                    // Select HTML Content block by default
                    var blockType = new Rock.Model.BlockTypeService(rockContext)
                                    .GetByGuid(new Guid(Rock.SystemGuid.BlockType.HTML_CONTENT));
                    if (blockType != null)
                    {
                        ddlBlockType.SelectedValue = blockType.Id.ToString();
                    }
                    else
                    {
                        ddlBlockType.SelectedIndex = -1;
                    }

                    tbBlockName.Text = string.Empty;
                }
            }

            lAction.Text += hfBlockLocation.Value;

            pnlLists.Visible   = false;
            pnlDetails.Visible = true;
        }
        /// <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)
                {
                    Rock.Web.Cache.PageCache.FlushLayoutBlocks(_Page.LayoutId);
                }
                else
                {
                    _Page.FlushBlocks();
                }
            }

            PageUpdated = true;

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }
Example #12
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Rock.Model.Block block;

            int blockId = 0;

            if (!Int32.TryParse(hfBlockId.Value, out blockId))
            {
                blockId = 0;
            }

            if (blockId == 0)
            {
                block = new Rock.Model.Block();

                BlockLocation location = hfBlockLocation.Value.ConvertToEnum <BlockLocation>();
                if (location == BlockLocation.Layout)
                {
                    block.Layout = _page.Layout;
                    block.PageId = null;
                }
                else
                {
                    block.Layout = null;
                    block.PageId = _page.Id;
                }

                block.Zone = _zoneName;

                Rock.Model.Block lastBlock =
                    blockService.GetByLayoutAndPageIdAndZone(null, _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.Layout);
            }
            else
            {
                _page.FlushBlocks();
            }

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }
Example #13
0
        /// <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>();
                    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;
                    }
                }

                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 )
                {
                    Rock.Web.Cache.PageCache.FlushLayoutBlocks( _Page.LayoutId );
                }
                else
                {
                    _Page.FlushBlocks();
                }
            }

            PageUpdated = true;

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible = true;
        }
Example #14
0
        /// <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();
            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;
        }
Example #15
0
        /// <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;
        }