/// <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);
            string currentValue = null;

            if (ddlLayout.SelectedItem != null)
            {
                currentValue = ddlLayout.SelectedItem.Text;
            }

            ddlLayout.Items.Clear();
            var layouts = new LayoutService(rockContext).GetBySiteId(site.Id);

            foreach (var layout in layouts)
            {
                ddlLayout.Items.Add(new ListItem(layout.Name, layout.Id.ToString()));
            }

            if (currentValue.IsNotNullOrWhiteSpace())
            {
                var selectedLayout = layouts.FirstOrDefault(a => a.Name.Equals(currentValue, StringComparison.OrdinalIgnoreCase));
                if (selectedLayout != null)
                {
                    ddlLayout.SetValue(selectedLayout.Id);
                }
            }
        }
Ejemplo n.º 2
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()));
            }
        }
Ejemplo n.º 3
0
        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.º 4
0
        /// <summary>
        /// Binds the pages grid.
        /// </summary>
        protected void BindPagesGrid()
        {
            pnlPages.Visible = false;
            int siteId = PageParameter("siteId").AsInteger() ?? 0;

            if (siteId == 0)
            {
                // quit if the siteId can't be determined
                return;
            }

            hfSiteId.SetValue(siteId);
            pnlPages.Visible = true;

            LayoutService layoutService = new LayoutService();

            layoutService.RegisterLayouts(Request.MapPath("~"), SiteCache.Read(siteId), CurrentPersonId);
            var layouts = layoutService.Queryable().Where(a => a.SiteId.Equals(siteId)).Select(a => a.Id).ToList();

            var siteService = new SiteService();
            var pageId      = siteService.Get(siteId).DefaultPageId;

            var pageService = new PageService();
            var qry         = pageService.GetAllDescendents((int)pageId).AsQueryable().Where(a => layouts.Contains(a.LayoutId));

            string layoutFilter = gPagesFilter.GetUserPreference("Layout");

            if (!string.IsNullOrWhiteSpace(layoutFilter) && layoutFilter != Rock.Constants.All.Text)
            {
                qry = qry.Where(a => a.Layout.ToString() == layoutFilter);
            }

            SortProperty sortProperty = gPages.SortProperty;

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(q => q.Id);
            }

            gPages.DataSource = qry.ToList();
            gPages.DataBind();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Binds the group members grid.
        /// </summary>
        protected void BindLayoutsGrid()
        {
            pnlLayouts.Visible = false;

            int siteId = PageParameter("siteId").AsInteger();

            if (siteId == 0)
            {
                // quit if the siteId can't be determined
                return;
            }

            var rockContext = new RockContext();
            var site        = SiteCache.Read(siteId, rockContext);

            if (site == null)
            {
                return;
            }

            hfSiteId.SetValue(siteId);

            pnlLayouts.Visible = true;

            // Add any missing layouts
            LayoutService.RegisterLayouts(Request.MapPath("~"), site);

            LayoutService layoutService = new LayoutService(new RockContext());
            var           qry           = layoutService.Queryable().Where(a => a.SiteId.Equals(siteId));

            SortProperty sortProperty = gLayouts.SortProperty;

            if (sortProperty != null)
            {
                gLayouts.DataSource = qry.Sort(sortProperty).ToList();
            }
            else
            {
                gLayouts.DataSource = qry.OrderBy(l => l.Name).ToList();
            }

            gLayouts.DataBind();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            int siteId = PageParameter("siteId").AsInteger();

            if (siteId == 0)
            {
                // quit if the siteId can't be determined
                return;
            }
            LayoutService.RegisterLayouts(Request.MapPath("~"), SiteCache.Read(siteId));
            LayoutService layoutService = new LayoutService(new RockContext());
            var           layouts       = layoutService.Queryable().Where(a => a.SiteId.Equals(siteId)).ToList();

            ddlLayoutFilter.DataSource = layouts;
            ddlLayoutFilter.DataBind();
            ddlLayoutFilter.Items.Insert(0, Rock.Constants.All.ListItem);
            ddlLayoutFilter.Visible = layouts.Any();
            ddlLayoutFilter.SetValue(gPagesFilter.GetUserPreference("Layout"));
        }
Ejemplo n.º 7
0
        /// <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();
                PageService       pageService       = new PageService(rockContext);
                SiteService       siteService       = new SiteService(rockContext);
                SiteDomainService siteDomainService = new SiteDomainService(rockContext);
                bool              newSite           = false;

                int siteId = hfSiteId.Value.AsInteger();

                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.ChangePasswordPageId      = ppChangePasswordPage.PageId;
                site.ChangePasswordPageRouteId = ppChangePasswordPage.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.RequiresEncryption        = cbRequireEncryption.Checked;
                site.EnabledForShortening      = cbEnableForShortening.Checked;
                site.EnableMobileRedirect      = cbEnableMobileRedirect.Checked;
                site.MobilePageId              = ppMobilePage.PageId;
                site.ExternalUrl               = tbExternalURL.Text;
                site.AllowedFrameDomains       = tbAllowedFrameDomains.Text;
                site.RedirectTablets           = cbRedirectTablets.Checked;
                site.EnablePageViews           = cbEnablePageViews.Checked;

                site.AllowIndexing         = cbAllowIndexing.Checked;
                site.IsIndexEnabled        = cbEnableIndexing.Checked;
                site.IndexStartingLocation = tbIndexStartingLocation.Text;

                site.PageHeaderContent = cePageHeaderContent.Text;

                int?existingIconId = null;
                if (site.FavIconBinaryFileId != imgSiteIcon.BinaryFileId)
                {
                    existingIconId           = site.FavIconBinaryFileId;
                    site.FavIconBinaryFileId = imgSiteIcon.BinaryFileId;
                }

                int?existingLogoId = null;
                if (site.SiteLogoBinaryFileId != imgSiteLogo.BinaryFileId)
                {
                    existingLogoId            = site.SiteLogoBinaryFileId;
                    site.SiteLogoBinaryFileId = imgSiteLogo.BinaryFileId;
                }

                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);
                }

                int order = 0;
                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);
                    }
                    sd.Order = order++;
                }

                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();

                    SaveAttributes(new Page().TypeId, "SiteId", site.Id.ToString(), PageAttributesState, rockContext);

                    if (existingIconId.HasValue)
                    {
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                        var binaryFile = binaryFileService.Get(existingIconId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    if (existingLogoId.HasValue)
                    {
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                        var binaryFile = binaryFileService.Get(existingLogoId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

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

                // add/update for the InteractionChannel for this site and set the RetentionPeriod
                var interactionChannelService   = new InteractionChannelService(rockContext);
                int channelMediumWebsiteValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.INTERACTIONCHANNELTYPE_WEBSITE.AsGuid()).Id;
                var interactionChannelForSite   = interactionChannelService.Queryable()
                                                  .Where(a => a.ChannelTypeMediumValueId == channelMediumWebsiteValueId && a.ChannelEntityId == site.Id).FirstOrDefault();

                if (interactionChannelForSite == null)
                {
                    interactionChannelForSite = new InteractionChannel();
                    interactionChannelForSite.ChannelTypeMediumValueId = channelMediumWebsiteValueId;
                    interactionChannelForSite.ChannelEntityId          = site.Id;
                    interactionChannelService.Add(interactionChannelForSite);
                }

                interactionChannelForSite.Name = site.Name;
                interactionChannelForSite.RetentionDuration     = nbPageViewRetentionPeriodDays.Text.AsIntegerOrNull();
                interactionChannelForSite.ComponentEntityTypeId = EntityTypeCache.Get <Rock.Model.Page>().Id;

                rockContext.SaveChanges();


                // Create the default page is this is a new site
                if (!site.DefaultPageId.HasValue && newSite)
                {
                    var siteCache = SiteCache.Get(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 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();
                    }
                }

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

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Binds the pages grid.
        /// </summary>
        protected void BindPagesGrid()
        {
            pnlPages.Visible = false;
            int siteId = PageParameter("siteId").AsInteger();

            if (siteId == 0)
            {
                // quit if the siteId can't be determined
                return;
            }

            hfSiteId.SetValue(siteId);
            pnlPages.Visible = true;

            // Question: Is this RegisterLayouts necessary here?  Since if it's a new layout
            // there would not be any pages on them (which is our concern here).
            // It seems like it should be the concern of some other part of the puzzle.
            LayoutService.RegisterLayouts(Request.MapPath("~"), SiteCache.Read(siteId));
            //var layouts = layoutService.Queryable().Where( a => a.SiteId.Equals( siteId ) ).Select( a => a.Id ).ToList();

            // Find all the pages that are related to this site...
            // 1) pages used by one of this site's layouts and
            // 2) the site's 'special' pages used directly by the site.
            var rockContext = new RockContext();
            var siteService = new SiteService(rockContext);
            var pageService = new PageService(rockContext);

            var site = siteService.Get(siteId);

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

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

                string layoutFilter = gPagesFilter.GetUserPreference("Layout");
                if (!string.IsNullOrWhiteSpace(layoutFilter) && layoutFilter != Rock.Constants.All.Text)
                {
                    qry = qry.Where(a => a.Layout.ToString() == layoutFilter);
                }

                SortProperty sortProperty = gPages.SortProperty;
                if (sortProperty != null)
                {
                    qry = qry.Sort(sortProperty);
                }
                else
                {
                    qry = qry
                          .OrderBy(t => t.Layout.Name)
                          .ThenBy(t => t.InternalName);
                }

                gPages.DataSource = qry.ToList();
                gPages.DataBind();
            }
        }
Ejemplo n.º 9
0
        /// <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 = hfSiteId.Value.AsInteger();

                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.ChangePasswordPageId        = ppChangePasswordPage.PageId;
                site.ChangePasswordPageRouteId   = ppChangePasswordPage.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.RequiresEncryption          = cbRequireEncryption.Checked;
                site.EnableMobileRedirect        = cbEnableMobileRedirect.Checked;
                site.MobilePageId                = ppMobilePage.PageId;
                site.ExternalUrl                 = tbExternalURL.Text;
                site.AllowedFrameDomains         = tbAllowedFrameDomains.Text;
                site.RedirectTablets             = cbRedirectTablets.Checked;
                site.EnablePageViews             = cbEnablePageViews.Checked;
                site.PageViewRetentionPeriodDays = nbPageViewRetentionPeriodDays.Text.AsIntegerOrNull();

                site.AllowIndexing     = cbAllowIndexing.Checked;
                site.PageHeaderContent = cePageHeaderContent.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, Authorization.EDIT);
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.ADMINISTRATE);
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.APPROVE);
                    }
                });

                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);
            }
        }
Ejemplo n.º 10
0
        /// <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)
            {
                using (new Rock.Data.UnitOfWorkScope())
                {
                    SiteService       siteService       = new SiteService();
                    SiteDomainService siteDomainService = new SiteDomainService();
                    bool newSite = false;

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

                    if (siteId == 0)
                    {
                        newSite = true;
                        site    = new Rock.Model.Site();
                        siteService.Add(site, CurrentPersonId);
                    }
                    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.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, CurrentPersonId);
                    }

                    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;
                    }

                    RockTransactionScope.WrapTransaction(() =>
                    {
                        siteService.Save(site, CurrentPersonId);

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

                    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
                        var layoutService = new LayoutService();
                        layoutService.RegisterLayouts(Request.MapPath("~"), siteCache, CurrentPersonId);

                        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();
                            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, CurrentPersonId);
                            pageService.Save(page, CurrentPersonId);

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

                            SiteCache.Flush(site.Id);
                        }
                    }
                }

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

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }