Exemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e)
        {
            bool canDelete = false;

            var         rockContext = new RockContext();
            SiteService siteService = new SiteService(rockContext);
            Site        site        = siteService.Get(int.Parse(hfSiteId.Value));

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

                siteService.Delete(site);

                rockContext.SaveChanges();

                SiteCache.Flush(site.Id);
            }

            NavigateToParentPage();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        public void ShowDetail(int siteId)
        {
            pnlDetails.Visible = false;

            Site site = null;

            if (!siteId.Equals(0))
            {
                site = new SiteService(new RockContext()).Get(siteId);
            }

            if (site == null)
            {
                site = new Site {
                    Id = 0
                };
                site.SiteDomains = new List <SiteDomain>();
                site.Theme       = RockPage.Layout.Site.Theme;
            }

            pnlDetails.Visible = true;
            hfSiteId.Value     = site.Id.ToString();

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Rock.Model.Site.FriendlyTypeName);
            }

            if (site.IsSystem)
            {
                nbEditModeMessage.Text = EditModeMessage.System(Rock.Model.Site.FriendlyTypeName);
            }

            if (readOnly)
            {
                btnEdit.Visible   = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails(site);
            }
            else
            {
                btnEdit.Visible   = true;
                btnDelete.Visible = !site.IsSystem;
                if (site.Id > 0)
                {
                    ShowReadonlyDetails(site);
                }
                else
                {
                    ShowEditDetails(site);
                }
            }
        }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        public void ShowDetail( int siteId )
        {
            pnlDetails.Visible = false;

            Site site = null;

            if ( !siteId.Equals( 0 ) )
            {
                site = new SiteService( new RockContext() ).Get( siteId );
            }

            if (site == null)
            {
                site = new Site { Id = 0 };
                site.SiteDomains = new List<SiteDomain>();
                site.Theme = RockPage.Layout.Site.Theme;
            }

            pnlDetails.Visible = true;
            hfSiteId.Value = site.Id.ToString();

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Rock.Model.Site.FriendlyTypeName );
            }

            if ( site.IsSystem )
            {
                nbEditModeMessage.Text = EditModeMessage.System( Rock.Model.Site.FriendlyTypeName );
            }

            if ( readOnly )
            {
                btnEdit.Visible = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails( site );
            }
            else
            {
                btnEdit.Visible = true;
                btnDelete.Visible = !site.IsSystem;
                if ( site.Id > 0 )
                {
                    ShowReadonlyDetails( site );
                }
                else
                {
                    ShowEditDetails( site );
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Click event of the btnDeleteConfirm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDeleteConfirm_Click(object sender, EventArgs e)
        {
            bool canDelete = false;

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

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

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

                pageService.DeleteRange(pageQry);

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

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

                siteService.Delete(site);

                rockContext.SaveChanges();

                SiteCache.Flush(site.Id);
            }

            NavigateToParentPage();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves the attribute values.
        /// </summary>
        /// <param name="personId">The person id.</param>
        public void SaveAttributeValues(int?personId)
        {
            Rock.Model.SiteService siteService = new Model.SiteService();
            Rock.Model.Site        siteModel   = siteService.Get(this.Id);
            if (siteModel != null)
            {
                siteModel.LoadAttributes();

                if (siteModel.Attributes != null)
                {
                    foreach (var attribute in siteModel.Attributes)
                    {
                        Rock.Attribute.Helper.SaveAttributeValues(siteModel, attribute.Value, this.AttributeValues[attribute.Key], personId);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the Click event of the btnCompileTheme 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 btnCompileTheme_Click(object sender, EventArgs e)
        {
            var         rockContext = new RockContext();
            SiteService siteService = new SiteService(rockContext);
            Site        site        = siteService.Get(hfSiteId.Value.AsInteger());

            string messages = string.Empty;
            var    theme    = new RockTheme(site.Theme);
            bool   success  = theme.Compile(out messages);

            if (success)
            {
                mdThemeCompile.Show("Theme was successfully compiled.", ModalAlertType.Information);
            }
            else
            {
                mdThemeCompile.Show(string.Format("An error occurred compiling the theme {0}. Message: {1}.", site.Theme, messages), ModalAlertType.Warning);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns Site object from cache.  If site does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static SiteCache Read(int id)
        {
            string cacheKey = SiteCache.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            SiteCache   site  = cache[cacheKey] as SiteCache;

            if (site != null)
            {
                return(site);
            }
            else
            {
                Rock.Model.SiteService siteService = new Model.SiteService();
                Rock.Model.Site        siteModel   = siteService.Get(id);
                if (siteModel != null)
                {
                    site = new SiteCache(siteModel);

                    siteModel.LoadAttributes();

                    foreach (var attribute in siteModel.Attributes)
                    {
                        site.AttributeIds.Add(attribute.Value.Id);
                    }

                    site.AttributeValues = siteModel.AttributeValues;

                    cache.Set(cacheKey, site, new CacheItemPolicy());

                    return(site);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                SiteService siteService = new SiteService();
                Site site = siteService.Get(int.Parse(hfSiteId.Value));
                if (site != null)
                {
                    string errorMessage;
                    if (!siteService.CanDelete(site, out errorMessage))
                    {
                        mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    siteService.Delete(site, CurrentPersonId);
                    siteService.Save(site, CurrentPersonId);

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

            NavigateToParentPage();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        public void ShowDetail(int siteId)
        {
            pnlDetails.Visible = false;

            Site site = null;

            if (!siteId.Equals(0))
            {
                site = new SiteService(new RockContext()).Get(siteId);
                pdAuditDetails.SetEntity(site, ResolveRockUrl("~"));
            }

            if (site == null)
            {
                site = new Site {
                    Id = 0
                };
                site.SiteDomains = new List <SiteDomain>();
                site.Theme       = RockPage.Layout.Site.Theme;
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }
            else
            {
                if (site.DefaultPageId.HasValue)
                {
                    lVisitSite.Text = string.Format(@"<a href=""{0}{1}"" target=""_blank""><span class=""label label-info"">Visit Site</span></a>", ResolveRockUrl("~/page/"), site.DefaultPageId);
                }
            }

            Guid fileTypeGuid = GetAttributeValue("DefaultFileType").AsGuid();

            imgSiteIcon.BinaryFileTypeGuid = fileTypeGuid;

            // set theme compile button
            if (!new RockTheme(site.Theme).AllowsCompile)
            {
                btnCompileTheme.Enabled = false;
                btnCompileTheme.Text    = "Theme Doesn't Support Compiling";
            }

            pnlDetails.Visible = true;
            hfSiteId.Value     = site.Id.ToString();

            cePageHeaderContent.Text = site.PageHeaderContent;
            cbAllowIndexing.Checked  = site.AllowIndexing;

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Rock.Model.Site.FriendlyTypeName);
            }

            if (site.IsSystem)
            {
                nbEditModeMessage.Text = EditModeMessage.System(Rock.Model.Site.FriendlyTypeName);
            }

            if (readOnly)
            {
                btnEdit.Visible   = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails(site);
            }
            else
            {
                btnEdit.Visible   = true;
                btnDelete.Visible = !site.IsSystem;
                if (site.Id > 0)
                {
                    ShowReadonlyDetails(site);
                }
                else
                {
                    ShowEditDetails(site);
                }
            }
        }
Exemplo 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;
            SiteDomain sd;
            bool newSite = false;

            using ( new UnitOfWorkScope() )
            {
                SiteService siteService = new SiteService();
                SiteDomainService siteDomainService = new SiteDomainService();

                int siteId = 0;
                if ( !int.TryParse( hfSiteId.Value, out siteId ) )
                {
                    siteId = 0;
                }

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.Model.Site();
                    siteService.Add( site, CurrentPersonId );
                }
                else
                {
                    site = siteService.Get( siteId );
                    foreach ( var domain in site.SiteDomains.ToList() )
                    {
                        siteDomainService.Delete( domain, CurrentPersonId );
                    }

                    site.SiteDomains.Clear();
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = int.Parse( ddlDefaultPage.SelectedValue );

                foreach ( string domain in tbSiteDomains.Text.SplitDelimitedValues() )
                {
                    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;

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

                siteService.Save( site, CurrentPersonId );

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

                SiteCache.Flush( site.Id );

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible = true;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        public void ShowDetail( int siteId )
        {
            pnlDetails.Visible = false;

            Site site = null;

            if ( !siteId.Equals( 0 ) )
            {
                site = new SiteService( new RockContext() ).Get( siteId );
                pdAuditDetails.SetEntity( site, ResolveRockUrl( "~" ) );
            }

            if ( site == null )
            {
                site = new Site { Id = 0 };
                site.SiteDomains = new List<SiteDomain>();
                site.Theme = RockPage.Layout.Site.Theme;
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            // set theme compile button
            if ( ! new RockTheme(site.Theme ).AllowsCompile)
            {
                btnCompileTheme.Enabled = false;
                btnCompileTheme.Text = "Theme Doesn't Support Compiling";
            }

            pnlDetails.Visible = true;
            hfSiteId.Value = site.Id.ToString();

            cePageHeaderContent.Text = site.PageHeaderContent;
            cbAllowIndexing.Checked = site.AllowIndexing;

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Rock.Model.Site.FriendlyTypeName );
            }

            if ( site.IsSystem )
            {
                nbEditModeMessage.Text = EditModeMessage.System( Rock.Model.Site.FriendlyTypeName );
            }

            if ( readOnly )
            {
                btnEdit.Visible = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails( site );
            }
            else
            {
                btnEdit.Visible = true;
                btnDelete.Visible = !site.IsSystem;
                if ( site.Id > 0 )
                {
                    ShowReadonlyDetails( site );
                }
                else
                {
                    ShowEditDetails( site );
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        public void ShowDetail(int siteId)
        {
            pnlDetails.Visible = false;

            Site site = null;

            if (!siteId.Equals(0))
            {
                site = new SiteService(new RockContext()).Get(siteId);
                pdAuditDetails.SetEntity(site, ResolveRockUrl("~"));
            }

            if (site == null)
            {
                site = new Site {
                    Id = 0
                };
                site.SiteDomains = new List <SiteDomain>();
                site.Theme       = RockPage.Layout.Site.Theme;
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            // set theme compile button
            if (!new RockTheme(site.Theme).AllowsCompile)
            {
                btnCompileTheme.Enabled = false;
                btnCompileTheme.Text    = "Theme Doesn't Support Compiling";
            }

            pnlDetails.Visible = true;
            hfSiteId.Value     = site.Id.ToString();

            cePageHeaderContent.Text = site.PageHeaderContent;
            cbAllowIndexing.Checked  = site.AllowIndexing;

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Rock.Model.Site.FriendlyTypeName);
            }

            if (site.IsSystem)
            {
                nbEditModeMessage.Text = EditModeMessage.System(Rock.Model.Site.FriendlyTypeName);
            }

            if (readOnly)
            {
                btnEdit.Visible   = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails(site);
            }
            else
            {
                btnEdit.Visible   = true;
                btnDelete.Visible = !site.IsSystem;
                if (site.Id > 0)
                {
                    ShowReadonlyDetails(site);
                }
                else
                {
                    ShowEditDetails(site);
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        public void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("siteId"))
            {
                return;
            }

            pnlDetails.Visible = true;
            Site site = null;

            if (!itemKeyValue.Equals(0))
            {
                site = new SiteService().Get(itemKeyValue);
                lActionTitle.Text = ActionTitle.Edit(Rock.Model.Site.FriendlyTypeName);
            }
            else
            {
                site = new Site {
                    Id = 0
                };
                site.SiteDomains  = new List <SiteDomain>();
                site.Theme        = CurrentPage.Site.Theme;
                lActionTitle.Text = ActionTitle.Add(Rock.Model.Site.FriendlyTypeName);
            }

            LoadDropDowns();

            hfSiteId.Value = site.Id.ToString();

            tbSiteName.Text    = site.Name;
            tbDescription.Text = site.Description;
            ddlTheme.SetValue(site.Theme);
            ppDefaultPage.SetValue(site.DefaultPage);
            tbLoginPageReference.Text = site.LoginPageReference;

            tbSiteDomains.Text               = string.Join("\n", site.SiteDomains.Select(dom => dom.Domain).ToArray());
            tbFaviconUrl.Text                = site.FaviconUrl;
            tbAppleTouchIconUrl.Text         = site.AppleTouchIconUrl;
            tbFacebookAppId.Text             = site.FacebookAppId;
            tbFacebookAppSecret.Text         = site.FacebookAppSecret;
            tbRegistrationPageReference.Text = site.RegistrationPageReference;
            tbErrorPage.Text = site.ErrorPage;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Rock.Model.Site.FriendlyTypeName);
            }

            if (site.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(Rock.Model.Site.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(Rock.Model.Site.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            tbSiteName.ReadOnly                  = readOnly;
            tbDescription.ReadOnly               = readOnly;
            ddlTheme.Enabled                     = !readOnly;
            tbLoginPageReference.ReadOnly        = readOnly;
            ppDefaultPage.Enabled                = !readOnly;
            tbSiteDomains.ReadOnly               = readOnly;
            tbFaviconUrl.ReadOnly                = readOnly;
            tbAppleTouchIconUrl.ReadOnly         = readOnly;
            tbFacebookAppId.ReadOnly             = readOnly;
            tbFacebookAppSecret.ReadOnly         = readOnly;
            tbRegistrationPageReference.ReadOnly = readOnly;
            tbErrorPage.ReadOnly                 = readOnly;

            btnSave.Visible = !readOnly;
        }
Exemplo n.º 14
0
 private SiteCache(Rock.Model.Site model) : base(model)
 {
 }
Exemplo n.º 15
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;
            SiteDomain sd;
            bool       newSite = false;

            using (new UnitOfWorkScope())
            {
                SiteService       siteService       = new SiteService();
                SiteDomainService siteDomainService = new SiteDomainService();

                int siteId = 0;
                if (!int.TryParse(hfSiteId.Value, out siteId))
                {
                    siteId = 0;
                }

                if (siteId == 0)
                {
                    newSite = true;
                    site    = new Rock.Model.Site();
                    siteService.Add(site, CurrentPersonId);
                }
                else
                {
                    site = siteService.Get(siteId);
                    foreach (var domain in site.SiteDomains.ToList())
                    {
                        siteDomainService.Delete(domain, CurrentPersonId);
                    }

                    site.SiteDomains.Clear();
                }

                site.Name          = tbSiteName.Text;
                site.Description   = tbDescription.Text;
                site.Theme         = ddlTheme.Text;
                site.DefaultPageId = int.Parse(ddlDefaultPage.SelectedValue);

                foreach (string domain in tbSiteDomains.Text.SplitDelimitedValues())
                {
                    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;

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

                siteService.Save(site, CurrentPersonId);

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

                SiteCache.Flush(site.Id);

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible    = true;
            }
        }