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


C# PageService.Add方法代码示例

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


在下文中一共展示了PageService.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: btnSave_Click

        /// <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 )
        {
            Site site;

            if ( Page.IsValid )
            {
                var rockContext = new RockContext();
                SiteService siteService = new SiteService( rockContext );
                SiteDomainService siteDomainService = new SiteDomainService( rockContext );
                bool newSite = false;

                int siteId = int.Parse( hfSiteId.Value );

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.Model.Site();
                    siteService.Add( site );
                }
                else
                {
                    site = siteService.Get( siteId );
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = ppDefaultPage.PageId;
                site.DefaultPageRouteId = ppDefaultPage.PageRouteId;
                site.LoginPageId = ppLoginPage.PageId;
                site.LoginPageRouteId = ppLoginPage.PageRouteId;
                site.CommunicationPageId = ppCommunicationPage.PageId;
                site.CommunicationPageRouteId = ppCommunicationPage.PageRouteId;
                site.RegistrationPageId = ppRegistrationPage.PageId;
                site.RegistrationPageRouteId = ppRegistrationPage.PageRouteId;
                site.PageNotFoundPageId = ppPageNotFoundPage.PageId;
                site.PageNotFoundPageRouteId = ppPageNotFoundPage.PageRouteId;
                site.ErrorPage = tbErrorPage.Text;
                site.GoogleAnalyticsCode = tbGoogleAnalytics.Text;
                site.FacebookAppId = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList<string>();
                site.SiteDomains = site.SiteDomains ?? new List<SiteDomain>();

                // Remove any deleted domains
                foreach ( var domain in site.SiteDomains.Where( w => !currentDomains.Contains( w.Domain ) ).ToList() )
                {
                    site.SiteDomains.Remove( domain );
                    siteDomainService.Delete( domain );
                }

                foreach ( string domain in currentDomains )
                {
                    SiteDomain sd = site.SiteDomains.Where( d => d.Domain == domain ).FirstOrDefault();
                    if ( sd == null )
                    {
                        sd = new SiteDomain();
                        sd.Domain = domain;
                        sd.Guid = Guid.NewGuid();
                        site.SiteDomains.Add( sd );
                    }
                }

                if ( !site.DefaultPageId.HasValue && !newSite )
                {
                    ppDefaultPage.ShowErrorMessage( "Default Page is required." );
                    return;
                }

                if ( !site.IsValid )
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction( () =>
                {
                    rockContext.SaveChanges();

                    if ( newSite )
                    {
                        Rock.Security.Authorization.CopyAuthorization( RockPage.Layout.Site, site, rockContext );
                    }
                } );

                SiteCache.Flush( site.Id );

                // Create the default page is this is a new site
                if ( !site.DefaultPageId.HasValue && newSite )
                {
                    var siteCache = SiteCache.Read( site.Id );

                    // Create the layouts for the site, and find the first one
                    LayoutService.RegisterLayouts( Request.MapPath( "~" ), siteCache );
//.........这里部分代码省略.........
开发者ID:Higherbound,项目名称:Higherbound-2016-website-upgrades,代码行数:101,代码来源:SiteDetail.ascx.cs

示例3: SavePages

        /// <summary>
        /// Recursively saves Pages and associated Blocks, PageRoutes and PageContexts.
        /// </summary>
        /// <param name="page">The current Page to save</param>
        /// <param name="newBlockTypes">List of BlockTypes not currently installed</param>
        /// <param name="personId">Id of the Person performing the "Import" operation</param>
        /// <param name="parentPageId">Id of the the current Page's parent</param>
        /// <param name="siteId">Id of the site the current Page is being imported into</param>
        private void SavePages( Page page, IEnumerable<BlockType> newBlockTypes, int personId, int parentPageId, int siteId )
        {
            // find layout
            var layoutService = new LayoutService();
            var layout = layoutService.GetBySiteId(siteId).Where( l => l.Name == page.Layout.Name && l.FileName == page.Layout.FileName ).FirstOrDefault();
            if ( layout == null )
            {
                layout = new Layout();
                layout.FileName = page.Layout.FileName;
                layout.Name = page.Layout.Name;
                layout.SiteId = siteId;
                layoutService.Add( layout, null );
                layoutService.Save( layout, null );
            }
            int layoutId = layout.Id;

            // Force shallow copies on entities so save operations are more atomic and don't get hosed
            // by nested object references.
            var pg = page.Clone(deepCopy: false);
            var blockTypes = newBlockTypes.ToList();
            pg.ParentPageId = parentPageId;
            pg.LayoutId = layoutId;

            var pageService = new PageService();
            pageService.Add( pg, personId );
            pageService.Save( pg, personId );

            var blockService = new BlockService();

            foreach ( var block in page.Blocks ?? new List<Block>() )
            {
                var blockType = blockTypes.FirstOrDefault( bt => block.BlockType.Path == bt.Path );
                var b = block.Clone( deepCopy: false );
                b.PageId = pg.Id;

                if ( blockType != null )
                {
                    b.BlockTypeId = blockType.Id;
                }

                blockService.Add( b, personId );
                blockService.Save( b, personId );
            }

            var pageRouteService = new PageRouteService();

            foreach ( var pageRoute in page.PageRoutes ?? new List<PageRoute>() )
            {
                var pr = pageRoute.Clone(deepCopy: false);
                pr.PageId = pg.Id;
                pageRouteService.Add( pr, personId );
                pageRouteService.Save( pr, personId );
            }

            var pageContextService = new PageContextService();

            foreach ( var pageContext in page.PageContexts ?? new List<PageContext>() )
            {
                var pc = pageContext.Clone(deepCopy: false);
                pc.PageId = pg.Id;
                pageContextService.Add( pc, personId );
                pageContextService.Save( pc, personId );
            }

            foreach ( var p in page.Pages ?? new List<Page>() )
            {
                SavePages( p, blockTypes, personId, pg.Id, siteId );
            }
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:77,代码来源:PackageService.cs

示例4: 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 ( Page.IsValid )
            {
                Rock.Model.Page page;

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

                int pageId = hfPageId.Value.AsInteger();
                if ( pageId == 0 )
                {
                    page = new Rock.Model.Page();

                    if ( _page != null )
                    {
                        page.ParentPageId = _page.Id;
                        page.LayoutId = _page.LayoutId;
                    }
                    else
                    {
                        page.ParentPageId = null;
                        page.LayoutId = PageCache.Read( RockPage.PageId ).LayoutId;
                    }

                    page.PageTitle = dtbPageName.Text;
                    page.BrowserTitle = page.PageTitle;
                    page.EnableViewState = true;
                    page.IncludeAdminFooter = true;
                    page.MenuDisplayChildPages = true;

                    Rock.Model.Page lastPage = pageService.GetByParentPageId( _page.Id ).OrderByDescending( b => b.Order ).FirstOrDefault();

                    if ( lastPage != null )
                    {
                        page.Order = lastPage.Order + 1;
                    }
                    else
                    {
                        page.Order = 0;
                    }

                    pageService.Add( page );
                }
                else
                {
                    page = pageService.Get( pageId );
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;
                page.InternalName = dtbPageName.Text;

                if ( page.IsValid )
                {
                    rockContext.SaveChanges();

                    PageCache.Flush( page.Id );
                    if ( _page != null )
                    {
                        Rock.Security.Authorization.CopyAuthorization( _page, page );
                        _page.FlushChildPages();
                    }

                    BindGrid();
                }

                rGrid.Visible = true;
                pnlDetails.Visible = false;
            }
        }
开发者ID:Higherbound,项目名称:Higherbound-2016-website-upgrades,代码行数:75,代码来源:Pages.ascx.cs


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