Esempio n. 1
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="site">The site.</param>
        private void ShowReadonlyDetails(Rock.Model.Site site)
        {
            SetEditMode(false);

            hfSiteId.SetValue(site.Id);
            lReadOnlyTitle.Text = site.Name.FormatAsHtmlTitle();

            lSiteDescription.Text = site.Description;

            DescriptionList descriptionList = new DescriptionList();

            descriptionList.Add("Domain(s)", site.SiteDomains.OrderBy(d => d.Order).Select(d => d.Domain).ToList().AsDelimited(", "));
            descriptionList.Add("Theme", site.Theme);
            descriptionList.Add("Default Page", site.DefaultPageRoute);
            lblMainDetails.Text = descriptionList.Html;
        }
        /// <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 );
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="site">The site.</param>
        private void ShowEditDetails(Rock.Model.Site site)
        {
            if (site.Id == 0)
            {
                nbDefaultPageNotice.Visible = true;
                lReadOnlyTitle.Text         = ActionTitle.Add(Rock.Model.Site.FriendlyTypeName).FormatAsHtmlTitle();
            }
            else
            {
                nbDefaultPageNotice.Visible = false;
                lReadOnlyTitle.Text         = site.Name.FormatAsHtmlTitle();
            }

            SetEditMode(true);

            LoadDropDowns();

            tbSiteName.ReadOnly = site.IsSystem;
            tbSiteName.Text     = site.Name;

            tbDescription.ReadOnly = site.IsSystem;
            tbDescription.Text     = site.Description;

            ddlTheme.Enabled = !site.IsSystem;
            ddlTheme.SetValue(site.Theme);

            imgSiteIcon.BinaryFileId = site.FavIconBinaryFileId;
            imgSiteLogo.BinaryFileId = site.SiteLogoBinaryFileId;

            if (site.DefaultPageRoute != null)
            {
                ppDefaultPage.SetValue(site.DefaultPageRoute);
            }
            else
            {
                ppDefaultPage.SetValue(site.DefaultPage);
            }

            if (site.LoginPageRoute != null)
            {
                ppLoginPage.SetValue(site.LoginPageRoute);
            }
            else
            {
                ppLoginPage.SetValue(site.LoginPage);
            }

            if (site.ChangePasswordPageRoute != null)
            {
                ppChangePasswordPage.SetValue(site.ChangePasswordPageRoute);
            }
            else
            {
                ppChangePasswordPage.SetValue(site.ChangePasswordPage);
            }

            if (site.CommunicationPageRoute != null)
            {
                ppCommunicationPage.SetValue(site.CommunicationPageRoute);
            }
            else
            {
                ppCommunicationPage.SetValue(site.CommunicationPage);
            }

            if (site.RegistrationPageRoute != null)
            {
                ppRegistrationPage.SetValue(site.RegistrationPageRoute);
            }
            else
            {
                ppRegistrationPage.SetValue(site.RegistrationPage);
            }

            if (site.PageNotFoundPageRoute != null)
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPageRoute);
            }
            else
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPage);
            }

            tbErrorPage.Text = site.ErrorPage;

            tbSiteDomains.Text            = string.Join("\n", site.SiteDomains.OrderBy(d => d.Order).Select(d => d.Domain).ToArray());
            tbGoogleAnalytics.Text        = site.GoogleAnalyticsCode;
            cbRequireEncryption.Checked   = site.RequiresEncryption;
            cbEnableForShortening.Checked = site.EnabledForShortening;

            cbEnableMobileRedirect.Checked = site.EnableMobileRedirect;
            ppMobilePage.SetValue(site.MobilePage);
            tbExternalURL.Text         = site.ExternalUrl;
            tbAllowedFrameDomains.Text = site.AllowedFrameDomains;
            cbRedirectTablets.Checked  = site.RedirectTablets;
            cbEnablePageViews.Checked  = site.EnablePageViews;

            int channelMediumWebsiteValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.INTERACTIONCHANNELTYPE_WEBSITE.AsGuid()).Id;
            var interactionChannelForSite   = new InteractionChannelService(new RockContext()).Queryable()
                                              .Where(a => a.ChannelTypeMediumValueId == channelMediumWebsiteValueId && a.ChannelEntityId == site.Id).FirstOrDefault();

            if (interactionChannelForSite != null)
            {
                nbPageViewRetentionPeriodDays.Text = interactionChannelForSite.RetentionDuration.ToString();
            }

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

            // disable the indexing features if indexing on site is disabled
            var siteEntityType = EntityTypeCache.Get("Rock.Model.Site");

            if (siteEntityType != null && !siteEntityType.IsIndexingEnabled)
            {
                cbEnableIndexing.Visible        = false;
                tbIndexStartingLocation.Visible = false;
            }

            var attributeService     = new AttributeService(new RockContext());
            var siteIdQualifierValue = site.Id.ToString();

            PageAttributesState = attributeService.GetByEntityTypeId(new Page().TypeId, true).AsQueryable()
                                  .Where(a =>
                                         a.EntityTypeQualifierColumn.Equals("SiteId", StringComparison.OrdinalIgnoreCase) &&
                                         a.EntityTypeQualifierValue.Equals(siteIdQualifierValue))
                                  .OrderBy(a => a.Order)
                                  .ThenBy(a => a.Name)
                                  .ToList();
            BindPageAttributesGrid();

            SetControlsVisiblity();
        }
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="group">The group.</param>
        private void ShowEditDetails(Rock.Model.Site site)
        {
            if (site.Id == 0)
            {
                nbDefaultPageNotice.Visible = true;
                lReadOnlyTitle.Text         = ActionTitle.Add(Rock.Model.Site.FriendlyTypeName).FormatAsHtmlTitle();
            }
            else
            {
                nbDefaultPageNotice.Visible = false;
                lReadOnlyTitle.Text         = site.Name.FormatAsHtmlTitle();
            }

            SetEditMode(true);

            LoadDropDowns();

            tbSiteName.ReadOnly = site.IsSystem;
            tbSiteName.Text     = site.Name;

            tbDescription.ReadOnly = site.IsSystem;
            tbDescription.Text     = site.Description;

            ddlTheme.Enabled = !site.IsSystem;
            ddlTheme.SetValue(site.Theme);

            if (site.DefaultPageRoute != null)
            {
                ppDefaultPage.SetValue(site.DefaultPageRoute);
            }
            else
            {
                ppDefaultPage.SetValue(site.DefaultPage);
            }

            if (site.LoginPageRoute != null)
            {
                ppLoginPage.SetValue(site.LoginPageRoute);
            }
            else
            {
                ppLoginPage.SetValue(site.LoginPage);
            }

            if (site.ChangePasswordPageRoute != null)
            {
                ppChangePasswordPage.SetValue(site.ChangePasswordPageRoute);
            }
            else
            {
                ppChangePasswordPage.SetValue(site.ChangePasswordPage);
            }

            if (site.CommunicationPageRoute != null)
            {
                ppCommunicationPage.SetValue(site.CommunicationPageRoute);
            }
            else
            {
                ppCommunicationPage.SetValue(site.CommunicationPage);
            }

            if (site.RegistrationPageRoute != null)
            {
                ppRegistrationPage.SetValue(site.RegistrationPageRoute);
            }
            else
            {
                ppRegistrationPage.SetValue(site.RegistrationPage);
            }

            if (site.PageNotFoundPageRoute != null)
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPageRoute);
            }
            else
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPage);
            }

            tbErrorPage.Text = site.ErrorPage;

            tbSiteDomains.Text          = string.Join("\n", site.SiteDomains.Select(dom => dom.Domain).ToArray());
            tbGoogleAnalytics.Text      = site.GoogleAnalyticsCode;
            cbRequireEncryption.Checked = site.RequiresEncryption;

            cbEnableMobileRedirect.Checked = site.EnableMobileRedirect;
            ppMobilePage.SetValue(site.MobilePage);
            tbExternalURL.Text                 = site.ExternalUrl;
            tbAllowedFrameDomains.Text         = site.AllowedFrameDomains;
            cbRedirectTablets.Checked          = site.RedirectTablets;
            cbEnablePageViews.Checked          = site.EnablePageViews;
            nbPageViewRetentionPeriodDays.Text = site.PageViewRetentionPeriodDays.ToString();
            SetControlsVisiblity();
        }
Esempio n. 5
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);
            }
        }
        /// <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);
            }
        }
Esempio 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)
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                Site              site;
                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      = int.Parse(ppDefaultPage.SelectedValue);
                site.LoginPageReference = tbLoginPageReference.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);
                    }
                }

                site.FaviconUrl                = tbFaviconUrl.Text;
                site.AppleTouchIconUrl         = tbAppleTouchIconUrl.Text;
                site.FacebookAppId             = tbFacebookAppId.Text;
                site.FacebookAppSecret         = tbFacebookAppSecret.Text;
                site.RegistrationPageReference = tbRegistrationPageReference.Text;
                site.ErrorPage = tbErrorPage.Text;

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

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

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

                SiteCache.Flush(site.Id);
            }

            NavigateToParentPage();
        }
Esempio n. 8
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="group">The group.</param>
        private void ShowEditDetails(Rock.Model.Site site)
        {
            if (site.Id == 0)
            {
                nbDefaultPageNotice.Visible = true;
                lReadOnlyTitle.Text         = ActionTitle.Add(Rock.Model.Site.FriendlyTypeName).FormatAsHtmlTitle();
            }
            else
            {
                nbDefaultPageNotice.Visible = false;
                lReadOnlyTitle.Text         = site.Name.FormatAsHtmlTitle();
            }

            SetEditMode(true);

            LoadDropDowns();

            tbSiteName.ReadOnly = site.IsSystem;
            tbSiteName.Text     = site.Name;

            tbDescription.ReadOnly = site.IsSystem;
            tbDescription.Text     = site.Description;

            ddlTheme.Enabled = !site.IsSystem;
            ddlTheme.SetValue(site.Theme);

            if (site.DefaultPageRoute != null)
            {
                ppDefaultPage.SetValue(site.DefaultPageRoute);
            }
            else
            {
                ppDefaultPage.SetValue(site.DefaultPage);
            }

            if (site.LoginPageRoute != null)
            {
                ppLoginPage.SetValue(site.LoginPageRoute);
            }
            else
            {
                ppLoginPage.SetValue(site.LoginPage);
            }

            if (site.RegistrationPageRoute != null)
            {
                ppRegistrationPage.SetValue(site.RegistrationPageRoute);
            }
            else
            {
                ppRegistrationPage.SetValue(site.RegistrationPage);
            }

            if (site.PageNotFoundPageRoute != null)
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPageRoute);
            }
            else
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPage);
            }

            tbErrorPage.Text = site.ErrorPage;

            tbSiteDomains.Text       = string.Join("\n", site.SiteDomains.Select(dom => dom.Domain).ToArray());
            tbGoogleAnalytics.Text   = site.GoogleAnalyticsCode;
            tbFacebookAppId.Text     = site.FacebookAppId;
            tbFacebookAppSecret.Text = site.FacebookAppSecret;
        }
Esempio 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)
            {
                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);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="site">The site.</param>
        private void ShowEditDetails(Rock.Model.Site site)
        {
            if (site.Id == 0)
            {
                nbDefaultPageNotice.Visible = true;
                lReadOnlyTitle.Text         = ActionTitle.Add(Rock.Model.Site.FriendlyTypeName).FormatAsHtmlTitle();
            }
            else
            {
                nbDefaultPageNotice.Visible = false;
                lReadOnlyTitle.Text         = site.Name.FormatAsHtmlTitle();
            }

            SetEditMode(true);

            LoadDropDowns();

            tbSiteName.ReadOnly = site.IsSystem;
            tbSiteName.Text     = site.Name;

            tbDescription.ReadOnly = site.IsSystem;
            tbDescription.Text     = site.Description;

            ddlTheme.Enabled = !site.IsSystem;
            ddlTheme.SetValue(site.Theme);

            if (site.DefaultPageRoute != null)
            {
                ppDefaultPage.SetValue(site.DefaultPageRoute);
            }
            else
            {
                ppDefaultPage.SetValue(site.DefaultPage);
            }

            if (site.LoginPageRoute != null)
            {
                ppLoginPage.SetValue(site.LoginPageRoute);
            }
            else
            {
                ppLoginPage.SetValue(site.LoginPage);
            }

            if (site.ChangePasswordPageRoute != null)
            {
                ppChangePasswordPage.SetValue(site.ChangePasswordPageRoute);
            }
            else
            {
                ppChangePasswordPage.SetValue(site.ChangePasswordPage);
            }

            if (site.CommunicationPageRoute != null)
            {
                ppCommunicationPage.SetValue(site.CommunicationPageRoute);
            }
            else
            {
                ppCommunicationPage.SetValue(site.CommunicationPage);
            }

            if (site.RegistrationPageRoute != null)
            {
                ppRegistrationPage.SetValue(site.RegistrationPageRoute);
            }
            else
            {
                ppRegistrationPage.SetValue(site.RegistrationPage);
            }

            if (site.PageNotFoundPageRoute != null)
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPageRoute);
            }
            else
            {
                ppPageNotFoundPage.SetValue(site.PageNotFoundPage);
            }

            tbErrorPage.Text = site.ErrorPage;

            tbSiteDomains.Text          = string.Join("\n", site.SiteDomains.Select(dom => dom.Domain).ToArray());
            tbGoogleAnalytics.Text      = site.GoogleAnalyticsCode;
            cbRequireEncryption.Checked = site.RequiresEncryption;

            cbEnableMobileRedirect.Checked = site.EnableMobileRedirect;
            ppMobilePage.SetValue(site.MobilePage);
            tbExternalURL.Text         = site.ExternalUrl;
            tbAllowedFrameDomains.Text = site.AllowedFrameDomains;
            cbRedirectTablets.Checked  = site.RedirectTablets;
            cbEnablePageViews.Checked  = site.EnablePageViews;

            var attributeService     = new AttributeService(new RockContext());
            var siteIdQualifierValue = site.Id.ToString();

            PageAttributesState = attributeService.GetByEntityTypeId(new Page().TypeId).AsQueryable()
                                  .Where(a =>
                                         a.EntityTypeQualifierColumn.Equals("SiteId", StringComparison.OrdinalIgnoreCase) &&
                                         a.EntityTypeQualifierValue.Equals(siteIdQualifierValue))
                                  .OrderBy(a => a.Order)
                                  .ThenBy(a => a.Name)
                                  .ToList();
            BindPageAttributesGrid();

            SetControlsVisiblity();
        }