GetBySiteId() public method

Gets the Layout by site id.
public GetBySiteId ( int siteId ) : IQueryable
siteId int The site id.
return IQueryable
Ejemplo n.º 1
0
        /// <summary>
        /// Registers any layouts in a particular site's theme folder that do not currently have any layouts registered in Rock.
        /// </summary>
        /// <param name="physWebAppPath">A <see cref="System.String" /> containing the physical path to Rock on the server.</param>
        /// <param name="site">The site.</param>
        public static void RegisterLayouts(string physWebAppPath, SiteCache site)
        {
            // Dictionary for block types.  Key is path, value is friendly name
            var list = new Dictionary <string, string>();

            // Find all the layouts in theme layout folder...
            string layoutFolder = Path.Combine(physWebAppPath, string.Format("Themes\\{0}\\Layouts", site.Theme));

            // search for all layouts (aspx files) under the physical path
            var           layoutFiles = new List <string>();
            DirectoryInfo di          = new DirectoryInfo(layoutFolder);

            if (di.Exists)
            {
                foreach (var file in di.GetFiles("*.aspx", SearchOption.AllDirectories))
                {
                    layoutFiles.Add(Path.GetFileNameWithoutExtension(file.Name));
                }
            }

            var rockContext   = new RockContext();
            var layoutService = new LayoutService(rockContext);

            // Get a list of the layout filenames already registered
            var registered = layoutService.GetBySiteId(site.Id).Select(l => l.FileName).Distinct().ToList();

            // for each unregistered layout
            foreach (string layoutFile in layoutFiles.Except(registered, StringComparer.CurrentCultureIgnoreCase))
            {
                // Create new layout record and save it
                Layout layout = new Layout();
                layout.SiteId   = site.Id;
                layout.FileName = layoutFile;
                layout.Name     = layoutFile.SplitCase();
                layout.Guid     = new Guid();

                layoutService.Add(layout);
            }

            rockContext.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers any layouts in a particular site's theme folder that do not currently have any layouts registered in Rock.
        /// </summary>
        /// <param name="physWebAppPath">A <see cref="System.String" /> containing the physical path to Rock on the server.</param>
        /// <param name="site">The site.</param>
        public static void RegisterLayouts( string physWebAppPath, SiteCache site )
        {
            // Dictionary for block types.  Key is path, value is friendly name
            var list = new Dictionary<string, string>();

            // Find all the layouts in theme layout folder...
            string layoutFolder = Path.Combine(physWebAppPath, string.Format("Themes\\{0}\\Layouts", site.Theme));

            // search for all layouts (aspx files) under the physical path
            var layoutFiles = new List<string>();
            DirectoryInfo di = new DirectoryInfo( layoutFolder );
            if ( di.Exists )
            {
                foreach(var file in di.GetFiles( "*.aspx", SearchOption.AllDirectories ))
                {
                    layoutFiles.Add( Path.GetFileNameWithoutExtension( file.Name ) );
                }
            }

            var rockContext = new RockContext();
            var layoutService = new LayoutService( rockContext );

            // Get a list of the layout filenames already registered
            var registered = layoutService.GetBySiteId( site.Id ).Select( l => l.FileName ).Distinct().ToList();

            // for each unregistered layout
            foreach ( string layoutFile in layoutFiles.Except( registered, StringComparer.CurrentCultureIgnoreCase ) )
            {
                // Create new layout record and save it
                Layout layout = new Layout();
                layout.SiteId = site.Id;
                layout.FileName = layoutFile;
                layout.Name = layoutFile.SplitCase();
                layout.Guid = new Guid();

                layoutService.Add( layout );
            }

            rockContext.SaveChanges();
        }
        /// <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 );

                    var layoutService = new LayoutService( rockContext );
                    var layouts = layoutService.GetBySiteId( siteCache.Id );
                    Layout layout = layouts.FirstOrDefault( l => l.FileName.Equals( "FullWidth", StringComparison.OrdinalIgnoreCase ) );
                    if ( layout == null )
                    {
                        layout = layouts.FirstOrDefault();
                    }
                    if ( layout != null )
                    {
                        var pageService = new PageService( rockContext );
                        var page = new Page();
                        page.LayoutId = layout.Id;
                        page.PageTitle = siteCache.Name + " Home Page";
                        page.InternalName = page.PageTitle;
                        page.BrowserTitle = page.PageTitle;
                        page.EnableViewState = true;
                        page.IncludeAdminFooter = true;
                        page.MenuDisplayChildPages = true;

                        var lastPage = pageService.GetByParentPageId( null ).
                            OrderByDescending( b => b.Order ).FirstOrDefault();

                        page.Order = lastPage != null ? lastPage.Order + 1 : 0;
                        pageService.Add( page );

                        rockContext.SaveChanges();

                        site = siteService.Get( siteCache.Id );
                        site.DefaultPageId = page.Id;

                        rockContext.SaveChanges();

                        SiteCache.Flush( site.Id );
                    }
                }

                var qryParams = new Dictionary<string, string>();
                qryParams["siteId"] = site.Id.ToString();

                NavigateToPage( RockPage.Guid, qryParams );
            }
        }
        /// <summary>
        /// Loads the layouts.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="site">The site.</param>
        private void LoadLayouts( RockContext rockContext, SiteCache site )
        {
            LayoutService.RegisterLayouts( Request.MapPath( "~" ), site );

            ddlLayout.Items.Clear();
            var layoutService = new LayoutService( rockContext );
            foreach ( var layout in layoutService.GetBySiteId( site.Id ) )
            {
                ddlLayout.Items.Add( new ListItem( layout.Name, layout.Id.ToString() ) );
            }
        }
Ejemplo n.º 5
0
        /// <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 );
            }
        }
Ejemplo n.º 6
0
 private void LoadLayouts(SiteCache Site)
 {
     ddlLayout.Items.Clear();
     var layoutService = new LayoutService();
     layoutService.RegisterLayouts( Request.MapPath( "~" ), Site, CurrentPersonId );
     foreach ( var layout in layoutService.GetBySiteId( Site.Id ) )
     {
         ddlLayout.Items.Add( new ListItem( layout.Name, layout.Id.ToString() ) );
     }
 }