GetByPageAndZone() 공개 메소드

Returns a collection of Blocks that are implemented in a Zone on a specific page.
public GetByPageAndZone ( int pageId, string zone ) : IQueryable
pageId int An that represents the Id of that a may be implemented on.
zone string A that represents the name of a page/layout zone that a may be implemented on.
리턴 IQueryable
예제 #1
0
        /// <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();
        }
예제 #2
0
        /// <summary>
        /// Binds the grids.
        /// </summary>
        private void BindGrids()
        {
            using ( var rockContext = new RockContext() )
            {
                BlockService blockService = new BlockService( rockContext );

                gLayoutBlocks.DataSource = blockService.GetByLayoutAndZone( _Page.LayoutId, _ZoneName )
                    .Select( b => new
                    {
                        b.Id,
                        b.Name,
                        BlockTypeName = b.BlockType.Name,
                        BlockTypePath = b.BlockType.Path
                    } )
                    .ToList();
                gLayoutBlocks.DataBind();

                gPageBlocks.DataSource = blockService.GetByPageAndZone( _Page.Id, _ZoneName )
                .Select( b => new
                {
                    b.Id,
                    b.Name,
                    BlockTypeName = b.BlockType.Name,
                    BlockTypePath = b.BlockType.Path
                } )
                .ToList();
                gPageBlocks.DataBind();
            }
        }
예제 #3
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;
        }
예제 #4
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;
        }
예제 #5
0
        /// <summary>
        /// Binds the page grid.
        /// </summary>
        private void BindPageGrid()
        {
            BlockService blockService = new BlockService( new RockContext() );
            int pageId = PageParameter( "EditPage" ).AsInteger();
            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId );
            string zoneName = this.PageParameter( "ZoneName" );

            gPageBlocks.DataSource = blockService.GetByPageAndZone( page.Id, zoneName ).ToList();
            gPageBlocks.DataBind();
        }
예제 #6
0
        /// <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();

            BindGrids();
        }
예제 #7
0
        /// <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 )
        {
            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" );

            blockService.Reorder( blockService.GetByPageAndZone( page.Id, zoneName ).ToList(), e.OldIndex, e.NewIndex, CurrentPersonId );

            BindGrids();
        }