示例#1
0
        private void DisplayEdit( int blockId )
        {
            phList.Visible = false;
            phDetails.Visible = true;

            using ( new Rock.Helpers.UnitOfWorkScope() )
            {
                Rock.Services.Cms.BlockService blockService = new Rock.Services.Cms.BlockService();

                if ( blockId > 0 )
                {
                    Rock.Models.Cms.Block block = blockService.GetBlock( Convert.ToInt32( PageParameter( "BlockId" ) ) );
                    if (block == null)
                        throw new System.Exception( "Invalid Block Id" );

                    tbPath.Text = block.Path;
                    tbName.Text = block.Name;
                    tbDescription.Text = block.Description;
                }
                else
                {
                    tbPath.Text = string.Empty;
                    tbName.Text = string.Empty;
                    tbDescription.Text = string.Empty;
                }
            }
        }
示例#2
0
        protected void lbSave_Click( object sender, EventArgs e )
        {
            using ( new Rock.Helpers.UnitOfWorkScope() )
            {
                Rock.Services.Cms.BlockService blockService = new Rock.Services.Cms.BlockService();

                Rock.Models.Cms.Block block = _action == "add" ?
                    new Rock.Models.Cms.Block() :
                    blockService.GetBlock( _blockId );

                block.Path = tbPath.Text;
                block.Name = tbName.Text;
                block.Description = tbDescription.Text;

                if ( _action == "add" )
                    blockService.AddBlock( block );
                blockService.Save( block, CurrentPersonId );

                Response.Redirect( "~/Bloc/list" );
            }
        }
示例#3
0
        private void DisplayList()
        {
            phList.Visible = true;
            phDetails.Visible = false;

            using ( new Rock.Helpers.UnitOfWorkScope() )
            {
                Rock.Services.Cms.BlockService blockService = new Rock.Services.Cms.BlockService();

                // Add any unregistered blocks
                foreach ( Rock.Models.Cms.Block block in blockService.GetUnregisteredBlocks( Request.MapPath( "~" ) ) )
                {
                    try
                    {
                        Control control = LoadControl( block.Path );
                        if ( control is Rock.Cms.CmsBlock )
                        {
                            block.Name = Path.GetFileNameWithoutExtension( block.Path );
                            block.Description = block.Path;

                            blockService.AddBlock( block );
                            blockService.Save( block, CurrentPersonId );
                        }
                    }
                    catch
                    {
                    }
                }

                gList.DataSource = blockService.Queryable().ToList();
                gList.DataBind();
            }
        }