CopyPage() public method

Copies the page.
public CopyPage ( int pageId, int currentPersonAliasId = null ) : Guid?
pageId int The page identifier.
currentPersonAliasId int The current person alias identifier.
return Guid?
示例#1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad( EventArgs e )
        {
            base.OnLoad( e );

            List<int> expandedPageIds = new List<int>();
            RockContext rockContext = new RockContext();
            PageService pageService = new PageService( rockContext );

            var allPages = pageService.Queryable( "PageContexts, PageRoutes" );

            foreach ( var page in allPages )
            {
                PageCache.Read( page );
            }

            foreach ( var block in new BlockService(rockContext).Queryable() )
            {
                BlockCache.Read( block );
            }

            foreach ( var blockType in new BlockTypeService( rockContext ).Queryable() )
            {
                BlockTypeCache.Read( blockType );
            }

            if ( Page.IsPostBack )
            {
                if ( Request.Form["__EVENTTARGET"] == "CopyPage" )
                {
                    // Fire event
                    int? intPageId = Request.Form["__EVENTARGUMENT"].AsIntegerOrNull();
                    if ( intPageId.HasValue )
                    {
                        Guid? pageGuid = pageService.CopyPage( intPageId.Value, CurrentPersonAliasId );
                        if ( pageGuid.HasValue )
                        {
                            NavigateToPage( pageGuid.Value, null );
                        }
                        else
                        {
                            NavigateToCurrentPage();
                        }
                    }
                }

                foreach ( string expandedId in hfExpandedIds.Value.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
                {
                    int id = 0;
                    if ( expandedId.StartsWith( "p" ) && expandedId.Length > 1 )
                    {
                        if ( int.TryParse( expandedId.Substring( 1 ), out id ) )
                        {
                            expandedPageIds.Add( id );
                        }
                    }
                }
            }
            else
            {
                string pageSearch = this.PageParameter( "pageSearch" );
                if ( !string.IsNullOrWhiteSpace( pageSearch ) )
                {
                    foreach ( Page page in pageService.Queryable().Where( a => a.InternalName.IndexOf( pageSearch ) >= 0 ) )
                    {
                        Page selectedPage = page;
                        while ( selectedPage != null )
                        {
                            selectedPage = selectedPage.ParentPage;
                            if ( selectedPage != null )
                            {
                                expandedPageIds.Add( selectedPage.Id );
                            }
                        }
                    }
                }
            }

            var sb = new StringBuilder();

            sb.AppendLine( "<ul id=\"treeview\">" );

            string rootPage = GetAttributeValue("RootPage");
            if ( ! string.IsNullOrEmpty( rootPage ) )
            {
                Guid pageGuid = rootPage.AsGuid();
                allPages = allPages.Where( a => a.ParentPage.Guid == pageGuid );
            }
            else
            {
                allPages = allPages.Where( a => a.ParentPageId == null );
            }

            foreach ( var page in allPages.OrderBy( a => a.Order ).ThenBy( a => a.InternalName ).Include(a => a.Blocks).ToList() )
            {
                sb.Append( PageNode( PageCache.Read( page ), expandedPageIds, rockContext ) );
            }

            sb.AppendLine( "</ul>" );

            lPages.Text = sb.ToString();
        }
示例#2
0
        /// <summary>
        /// Handles the Copy event of the rGrid 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 rGrid_Copy( object sender, RowEventArgs e )
        {
            var pageService = new PageService( new RockContext() );
            pageService.CopyPage( e.RowKeyId, CurrentPersonAliasId );

            BindGrid();
        }