当前位置: 首页>>代码示例>>C#>>正文


C# Model.PageService类代码示例

本文整理汇总了C#中Rock.Model.PageService的典型用法代码示例。如果您正苦于以下问题:C# PageService类的具体用法?C# PageService怎么用?C# PageService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PageService类属于Rock.Model命名空间,在下文中一共展示了PageService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyPage

        /// <summary>
        /// Copies the page.
        /// </summary>
        /// <param name="pageId">The page identifier.</param>
        /// <param name="currentPersonAliasId">The current person alias identifier.</param>
        public Guid? CopyPage( int pageId, int? currentPersonAliasId = null )
        {
            var rockContext = new RockContext();
            var pageService = new PageService( rockContext );
            Guid? newPageGuid = null;

            var page = pageService.Get( pageId );
            if ( page != null )
            {
                Dictionary<Guid, Guid> pageGuidDictionary = new Dictionary<Guid, Guid>();
                Dictionary<Guid, Guid> blockGuidDictionary = new Dictionary<Guid, Guid>();
                var newPage = GeneratePageCopy( page, pageGuidDictionary, blockGuidDictionary, currentPersonAliasId );

                pageService.Add( newPage );
                rockContext.SaveChanges();

                if ( newPage.ParentPageId.HasValue )
                {
                    PageCache.Flush( newPage.ParentPageId.Value );
                }
                newPageGuid= newPage.Guid;

                GenerateBlockAttributeValues( pageGuidDictionary, blockGuidDictionary, rockContext, currentPersonAliasId );
                GeneratePageBlockAuths( pageGuidDictionary, blockGuidDictionary, rockContext, currentPersonAliasId );
                CloneHtmlContent( blockGuidDictionary, rockContext, currentPersonAliasId );
            }

            return newPageGuid;
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:34,代码来源:PageService.Partial.cs

示例2: OnLoad

        /// <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>();
            PageService pageService = new PageService( new RockContext() );

            if ( Page.IsPostBack )
            {
                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\">" );
            var allPages = pageService.Queryable( "Pages, Blocks, Blocks.BlockType" ).ToList();
            foreach ( var page in allPages.Where( a => a.ParentPageId == null ).OrderBy( a => a.Order ).ThenBy( a => a.InternalName ) )
            {
                sb.Append( PageNode( page, expandedPageIds ) );
            }
            sb.AppendLine( "</ul>" );

            lPages.Text = sb.ToString();
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:57,代码来源:SiteMap.ascx.cs

示例3: FormatValue

        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue( System.Web.UI.Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
        {
            string formattedValue = string.Empty;

            if ( !string.IsNullOrWhiteSpace( value ) )
            {
                var service = new PageService();
                var page = service.Get( new Guid( value ) );
                if ( page != null )
                {
                    formattedValue = page.InternalName;
                }
            }

            return base.FormatValue( parentControl, formattedValue, null, condensed );
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:24,代码来源:PageReferenceFieldType.cs

示例4: OnInit

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );

            PageService pageService = new PageService();

            var sb = new StringBuilder();

            sb.AppendLine( "<ul id=\"treeview\">" );
            var allPages = pageService.Queryable( "Pages, Blocks, Blocks.BlockType" ).ToList();
            foreach ( var page in allPages.Where( a => a.ParentPageId == null ).OrderBy( a => a.Order ).ThenBy( a => a.InternalName ) )
            {
                sb.Append( PageNode( page ) );
            }
            sb.AppendLine( "</ul>" );

            lPages.Text = sb.ToString();
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:22,代码来源:SiteMap.ascx.cs

示例5: BindGrid

        private void BindGrid()
        {
            string type = PageParameter( "SearchType" );
            string term = PageParameter( "SearchTerm" );

            if ( !string.IsNullOrWhiteSpace( type ) && !string.IsNullOrWhiteSpace( term ) )
            {
                term = term.Trim();
                type = type.Trim().ToLower();

                var terms = term.Split( ' ' );

                var pageService = new PageService( new RockContext() );
                var pages = new List<Page>();

                switch ( type )
                {
                    case ( "name" ):
                        {
                            pages = pageService.Queryable().ToList().Where( p => Regex.IsMatch( p.PageTitle, String.Join("\\w* ", terms.Select(t => Regex.Escape(t))), RegexOptions.IgnoreCase ) ).ToList();
                            break;
                        }
                }

                if ( pages.Count == 1 )
                {
                    NavigateToPage( pages[0].Guid, null );
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    gPages.DataKeyNames = new string[] { "Guid" };
                    gPages.EntityTypeId = EntityTypeCache.GetId<Page>();
                    gPages.DataSource = pages.Select( p => new
                    {
                        p.Guid,
                        p.PageTitle,
                        Structure = ParentStructure( p ),
                        Site = p.Layout.Site.Name
                    } ).ToList();
                    gPages.DataBind();
                }
            }
        }
开发者ID:NewPointe,项目名称:Rockit,代码行数:44,代码来源:PageSearch.ascx.cs

示例6: OnInit

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );

            PageService pageService = new PageService( new RockContext() );

            List<int> expandedPageIds = new List<int>();

            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\">" );
            var allPages = pageService.Queryable( "Pages, Blocks, Blocks.BlockType" ).ToList();
            foreach ( var page in allPages.Where( a => a.ParentPageId == null ).OrderBy( a => a.Order ).ThenBy( a => a.InternalName ) )
            {
                sb.Append( PageNode( page, expandedPageIds ) );
            }
            sb.AppendLine( "</ul>" );

            lPages.Text = sb.ToString();
        }
开发者ID:CentralAZ,项目名称:Rockit-CentralAZ,代码行数:41,代码来源:SiteMap.ascx.cs

示例7: SetValuesOnSelect

 /// <summary>
 /// Sets the values on select.
 /// </summary>
 protected override void SetValuesOnSelect()
 {
     var pages = new PageService( new RockContext() ).Queryable().Where( p => ItemIds.Contains( p.Id.ToString() ) );
     this.SetValues( pages );
 }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:8,代码来源:PagePicker.cs

示例8: SetValueOnSelect

        /// <summary>
        /// Handles the Click event of the btnSelect control.
        /// </summary>
        protected override void SetValueOnSelect()
        {
            var page = new PageService( new RockContext() ).Get( int.Parse( ItemId ) );

            this.SetValue( page );
        }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:9,代码来源:PagePicker.cs

示例9: LoadDropDowns

        /// <summary>
        /// Loads the drop downs.
        /// </summary>
        private void LoadDropDowns()
        {
            PageService pageService = new PageService();
            List<Rock.Model.Page> allPages = pageService.Queryable().ToList();
            ddlDefaultPage.DataSource = allPages.OrderBy( a => a.PageSortHash );
            ddlDefaultPage.DataBind();

            ddlTheme.Items.Clear();
            DirectoryInfo di = new DirectoryInfo( this.Page.Request.MapPath( this.CurrentTheme ) );
            foreach ( var themeDir in di.Parent.EnumerateDirectories().OrderBy( a => a.Name ) )
            {
                ddlTheme.Items.Add( new ListItem( themeDir.Name, themeDir.Name ) );
            }
        }
开发者ID:jh2mhs8,项目名称:Rock-ChMS,代码行数:17,代码来源:Sites.ascx.cs

示例10: lbSave_Click

        protected void lbSave_Click( object sender, EventArgs e )
        {
            if ( updatePage )
            {
                var pageCache = PageCache.Read( RockPage.PageId );
                if ( pageCache != null &&
                    ( pageCache.PageTitle != tbName.Text || pageCache.Description != tbDesc.Text ) )
                {
                    var rockContext = new RockContext();
                    var service = new PageService( rockContext );
                    var page = service.Get( pageCache.Id );
                    page.InternalName = tbName.Text;
                    page.PageTitle = tbName.Text;
                    page.BrowserTitle = tbName.Text;
                    page.Description = tbDesc.Text;
                    rockContext.SaveChanges();

                    Rock.Web.Cache.PageCache.Flush( page.Id );
                    pageCache = PageCache.Read( RockPage.PageId );

                    var breadCrumb = RockPage.BreadCrumbs.Where( c => c.Url == RockPage.PageReference.BuildUrl() ).FirstOrDefault();
                    if ( breadCrumb != null )
                    {
                        breadCrumb.Name = pageCache.BreadCrumbText;
                    }
                }
            }

            SetAttributeValue( "Query", ceQuery.Text );
            SetAttributeValue( "QueryParams", tbParams.Text );
            SetAttributeValue( "UrlMask", tbUrlMask.Text );
            SetAttributeValue( "Columns", tbColumns.Text );
            SetAttributeValue( "ShowColumns", ddlHideShow.SelectedValue );
            SetAttributeValue( "FormattedOutput", ceFormattedOutput.Text );
            SetAttributeValue( "PersonReport", cbPersonReport.Checked.ToString() );
            SetAttributeValue( "MergeFields", tbMergeFields.Text );
            SaveAttributeValues();

            ShowView();
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:40,代码来源:DynamicData.ascx.cs

示例11: SetEditValue

        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="value">The value.</param>
        public override void SetEditValue( System.Web.UI.Control control, Dictionary<string, ConfigurationValue> configurationValues, string value )
        {
            if ( value != null )
            {
	            PagePicker ppPage = control as PagePicker;
    	        if ( ppPage != null )
        	    {
                    string[] valuePair = value.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries );

                    Page page = null;
                    PageRoute pageRoute = null;

                    //// Value is in format "Page.Guid,PageRoute.Guid"
                    //// If only the Page.Guid is specified this is just a reference to a page without a special route
                    //// In case the PageRoute record can't be found from PageRoute.Guid (maybe the pageroute was deleted), fall back to the Page without a PageRoute

                    if ( valuePair.Length == 2 )
                    {
                        Guid pageRouteGuid;
                        Guid.TryParse( valuePair[1], out pageRouteGuid );
                        pageRoute = new PageRouteService().Get( pageRouteGuid );
                    }

                    if ( pageRoute != null )
                    {
                        ppPage.SetValue( pageRoute );
                    }
                    else
                    {
                        if ( valuePair.Length > 0 )
                        {
                            Guid pageGuid;
                            Guid.TryParse( valuePair[0], out pageGuid );
                            page = new PageService().Get( pageGuid );
                        }

                        ppPage.SetValue( page );
                    }
        	    }
        	}
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:47,代码来源:PageReferenceFieldType.cs

示例12: lbSave_Click

        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click( object sender, EventArgs e )
        {
            if ( _updatePage )
            {
                var pageCache = PageCache.Read( RockPage.PageId );
                if ( pageCache != null &&
                    ( pageCache.PageTitle != tbName.Text || pageCache.Description != tbDesc.Text ) )
                {
                    var rockContext = new RockContext();
                    var service = new PageService( rockContext );
                    var page = service.Get( pageCache.Id );
                    page.InternalName = tbName.Text;
                    page.PageTitle = tbName.Text;
                    page.BrowserTitle = tbName.Text;
                    page.Description = tbDesc.Text;
                    rockContext.SaveChanges();

                    Rock.Web.Cache.PageCache.Flush( page.Id );
                    pageCache = PageCache.Read( RockPage.PageId );

                    var breadCrumb = RockPage.BreadCrumbs.Where( c => c.Url == RockPage.PageReference.BuildUrl() ).FirstOrDefault();
                    if ( breadCrumb != null )
                    {
                        breadCrumb.Name = pageCache.BreadCrumbText;
                    }
                }
            }

            SetAttributeValue( "Query", ceQuery.Text );
            SetAttributeValue( "Timeout", nbTimeout.Text );
            SetAttributeValue( "StoredProcedure", cbStoredProcedure.Checked.ToString() );
            SetAttributeValue( "QueryParams", tbParams.Text );
            SetAttributeValue( "UrlMask", tbUrlMask.Text );
            SetAttributeValue( "Columns", tbColumns.Text );
            SetAttributeValue( "ShowColumns", ddlHideShow.SelectedValue );
            SetAttributeValue( "FormattedOutput", ceFormattedOutput.Text );
            SetAttributeValue( "PageTitleLava", cePageTitleLava.Text );
            SetAttributeValue( "PersonReport", cbPersonReport.Checked.ToString() );

            SetAttributeValue( "ShowCommunicate", ( cbPersonReport.Checked && cbShowCommunicate.Checked ).ToString() );
            SetAttributeValue( "ShowMergePerson", ( cbPersonReport.Checked && cbShowMergePerson.Checked ).ToString() );
            SetAttributeValue( "ShowBulkUpdate", ( cbPersonReport.Checked && cbShowBulkUpdate.Checked ).ToString() );
            SetAttributeValue( "ShowExcelExport", cbShowExcelExport.Checked.ToString() );
            SetAttributeValue( "ShowMergeTemplate", cbShowMergeTemplate.Checked.ToString() );
            SetAttributeValue( "ShowGridFilter", cbShowGridFilter.Checked.ToString() );

            SetAttributeValue( "MergeFields", tbMergeFields.Text );
            SaveAttributeValues();

            mdEdit.Hide();
            pnlEditModel.Visible = false;
            upnlContent.Update();

            BuildControls( true );
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:60,代码来源:DynamicData.ascx.cs

示例13: masterPage_OnSave

        /// <summary>
        /// Handles the OnSave event of the masterPage 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 masterPage_OnSave( object sender, EventArgs e )
        {
            Page.Validate( BlockValidationGroup );
            if ( Page.IsValid && _pageId.HasValue )
            {
                var rockContext = new RockContext();
                var pageService = new PageService( rockContext );
                var routeService = new PageRouteService( rockContext );
                var contextService = new PageContextService( rockContext );

                var page = pageService.Get( _pageId.Value );

                // validate/check for removed routes
                var editorRoutes = tbPageRoute.Text.SplitDelimitedValues().Distinct();
                var databasePageRoutes = page.PageRoutes.ToList();
                var deletedRouteIds = new List<int>();
                var addedRoutes = new List<string>();

                if ( editorRoutes.Any() )
                {
                    // validate for any duplicate routes
                    var duplicateRoutes = routeService.Queryable()
                        .Where( r => editorRoutes.Contains( r.Route ) && r.PageId != _pageId )
                        .Select( r => r.Route )
                        .Distinct()
                        .ToList();

                    if ( duplicateRoutes.Any() )
                    {
                        // Duplicate routes
                        nbPageRouteWarning.Title = "Duplicate Route(s)";
                        nbPageRouteWarning.Text = string.Format( "<p>The page route <strong>{0}</strong>, already exists for another page. Please choose a different route name.</p>", duplicateRoutes.AsDelimited( "</strong> and <strong>" ) );
                        nbPageRouteWarning.Dismissable = true;
                        nbPageRouteWarning.Visible = true;
                        CurrentTab = "Advanced Settings";

                        rptProperties.DataSource = _tabs;
                        rptProperties.DataBind();
                        ShowSelectedPane();
                        return;
                    }
                }

                // validate if removed routes can be deleted
                foreach ( var pageRoute in databasePageRoutes )
                {
                    if ( !editorRoutes.Contains( pageRoute.Route ) )
                    {
                        // make sure the route can be deleted
                        string errorMessage;
                        if ( !routeService.CanDelete( pageRoute, out errorMessage ) )
                        {
                            nbPageRouteWarning.Text = string.Format( "The page route <strong>{0}</strong>, cannot be removed. {1}", pageRoute.Route, errorMessage );
                            nbPageRouteWarning.NotificationBoxType = NotificationBoxType.Warning;
                            nbPageRouteWarning.Dismissable = true;
                            nbPageRouteWarning.Visible = true;
                            CurrentTab = "Advanced Settings";

                            rptProperties.DataSource = _tabs;
                            rptProperties.DataBind();
                            ShowSelectedPane();
                            return;
                        }
                    }
                }

                // take care of deleted routes
                foreach ( var pageRoute in databasePageRoutes )
                {
                    if ( !editorRoutes.Contains( pageRoute.Route ) )
                    {
                        // if they removed the Route, remove it from the database
                        page.PageRoutes.Remove( pageRoute );

                        routeService.Delete( pageRoute );
                        deletedRouteIds.Add( pageRoute.Id );
                    }
                }

                // take care of added routes
                foreach ( string route in editorRoutes )
                {
                    // if they added the Route, add it to the database
                    if ( !databasePageRoutes.Any( a => a.Route == route ) )
                    {
                        var pageRoute = new PageRoute();
                        pageRoute.Route = route.TrimStart( new char[] { '/' } );
                        pageRoute.Guid = Guid.NewGuid();
                        page.PageRoutes.Add( pageRoute );
                        addedRoutes.Add( route );
                    }
                }

                int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0;
                if ( page.ParentPageId != parentPageId )
//.........这里部分代码省略.........
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:101,代码来源:PageProperties.ascx.cs

示例14: GenerateBlockAttributeValues

        /// <summary>
        /// This method takes the attribute values of the original blocks, and creates copies of them that point to the copied blocks. 
        /// In addition, any block attribute value pointing to a page in the original page tree is now updated to point to the
        /// corresponding page in the copied page tree.
        /// </summary>
        /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param>
        /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="currentPersonAliasId">The current person alias identifier.</param>
        private void GenerateBlockAttributeValues( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null )
        {
            var attributeValueService = new AttributeValueService( rockContext );
            var pageService = new PageService( rockContext );
            var blockService = new BlockService( rockContext );
            var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid();
            var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid();

            Dictionary<Guid, int> blockIntDictionary = blockService.Queryable()
                .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) )
                .ToDictionary( p => p.Guid, p => p.Id );

            var attributeValues = attributeValueService.Queryable().Where( a =>
                a.Attribute.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) )
                .ToList();

            foreach ( var attributeValue in attributeValues )
            {
                var newAttributeValue = attributeValue.Clone( false );
                newAttributeValue.CreatedByPersonAlias = null;
                newAttributeValue.CreatedByPersonAliasId = currentPersonAliasId;
                newAttributeValue.CreatedDateTime = RockDateTime.Now;
                newAttributeValue.ModifiedByPersonAlias = null;
                newAttributeValue.ModifiedByPersonAliasId = currentPersonAliasId;
                newAttributeValue.ModifiedDateTime = RockDateTime.Now;
                newAttributeValue.Id = 0;
                newAttributeValue.Guid = Guid.NewGuid();
                newAttributeValue.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == attributeValue.EntityId.Value ).FirstOrDefault().Key]];

                if ( attributeValue.Attribute.FieldType.Guid == Rock.SystemGuid.FieldType.PAGE_REFERENCE.AsGuid() )
                {
                    if ( pageGuidDictionary.ContainsKey( attributeValue.Value.AsGuid() ) )
                    {
                        newAttributeValue.Value = pageGuidDictionary[attributeValue.Value.AsGuid()].ToString();
                    }
                }

                attributeValueService.Add( newAttributeValue );
            }

            rockContext.SaveChanges();
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:51,代码来源:PageService.Partial.cs

示例15: btnDeleteConfirm_Click

        /// <summary>
        /// Handles the Click event of the btnDeleteConfirm 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 btnDeleteConfirm_Click( object sender, EventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            SiteService siteService = new SiteService( rockContext );
            Site site = siteService.Get( int.Parse( hfSiteId.Value ) );
            LayoutService layoutService = new LayoutService( rockContext );
            PageService pageService = new PageService( rockContext );
            PageViewService pageViewService = new PageViewService( rockContext );

            if ( site != null )
            {
                var sitePages = new List<int> {
                    site.DefaultPageId ?? -1,
                    site.LoginPageId ?? -1,
                    site.RegistrationPageId ?? -1,
                    site.PageNotFoundPageId ?? -1
                };

                foreach ( var pageView in pageViewService
                    .Queryable()
                    .Where( t =>
                        t.Page != null &&
                        t.Page.Layout != null &&
                        t.Page.Layout.SiteId == site.Id ) )
                {
                    pageView.Page = null;
                    pageView.PageId = null;
                }

                var pageQry = pageService.Queryable( "Layout" )
                    .Where( t =>
                        t.Layout.SiteId == site.Id ||
                        sitePages.Contains( t.Id ) );

                pageService.DeleteRange( pageQry );

                var layoutQry = layoutService.Queryable()
                    .Where( l =>
                        l.SiteId == site.Id );
                layoutService.DeleteRange( layoutQry );
                rockContext.SaveChanges( true );

                string errorMessage;
                canDelete = siteService.CanDelete( site, out errorMessage, includeSecondLvl: true );
                if ( !canDelete )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                siteService.Delete( site );

                rockContext.SaveChanges();

                SiteCache.Flush( site.Id );
            }

            NavigateToParentPage();
        }
开发者ID:,项目名称:,代码行数:66,代码来源:


注:本文中的Rock.Model.PageService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。