Beispiel #1
0
        public void UpdatePage(string id, Rock.CMS.DTO.Page Page)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.PageService PageService  = new Rock.CMS.PageService();
                Rock.CMS.Page        existingPage = PageService.Get(int.Parse(id));
                if (existingPage.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page);

                    if (existingPage.IsValid)
                    {
                        PageService.Save(existingPage, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
        protected override void OnLoad( EventArgs e )
        {
            if (!Page.IsPostBack && _page.Authorized( "Configure", CurrentUser ) )
            {
                Rock.CMS.PageService pageService = new Rock.CMS.PageService();
                Rock.CMS.Page page = pageService.Get( _page.Id );
                
                rptProperties.DataSource = tabs;
                rptProperties.DataBind();

                LoadDropdowns();

                tbPageName.Text = _page.Name;
                tbPageTitle.Text = _page.Title;
                ddlParentPage.SelectedValue = _page.ParentPage != null ? _page.ParentPage.Id.ToString() : "0";
                ddlLayout.Text = _page.Layout;
                ddlMenuWhen.SelectedValue = ( ( Int32 )_page.DisplayInNavWhen ).ToString();
                cbMenuDescription.Checked = _page.MenuDisplayDescription;
                cbMenuIcon.Checked = _page.MenuDisplayIcon;
                cbMenuChildPages.Checked = _page.MenuDisplayChildPages;
                cbRequiresEncryption.Checked = _page.RequiresEncryption;
                cbEnableViewState.Checked = _page.EnableViewstate;
                cbIncludeAdminFooter.Checked = _page.IncludeAdminFooter;
                tbCacheDuration.Text = _page.OutputCacheDuration.ToString();
                tbDescription.Text = _page.Description;
                tbPageRoute.Text = string.Join(",", page.PageRoutes.Select( route => route.Route ).ToArray());
              
            }

            base.OnLoad( e );

            if ( Page.IsPostBack )
                Rock.Attribute.Helper.SetErrorIndicators( phAttributes, _page );
        }
Beispiel #3
0
        public void ApiDeletePage(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                    Rock.CMS.Page        Page        = PageService.Get(int.Parse(id));
                    if (Page.Authorized("Edit", user))
                    {
                        PageService.Delete(Page, user.PersonId);
                        PageService.Save(Page, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #4
0
        public Rock.CMS.DTO.Page ApiGet(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                    Rock.CMS.Page        Page        = PageService.Get(int.Parse(id));
                    if (Page.Authorized("View", user))
                    {
                        return(Page.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #5
0
        public void DeletePage(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                Rock.CMS.Page        Page        = PageService.Get(int.Parse(id));
                if (Page.Authorized("Edit", currentUser))
                {
                    PageService.Delete(Page, currentUser.PersonId);
                    PageService.Save(Page, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #6
0
        protected void rGrid_Delete(object sender, RowEventArgs e)
        {
            Rock.CMS.Page page = pageService.Get(( int )rGrid.DataKeys[e.RowIndex]["id"]);
            if (page != null)
            {
                Rock.Web.Cache.Page.Flush(page.Id);

                pageService.Delete(page, CurrentPersonId);
                pageService.Save(page, CurrentPersonId);

                if (_page != null)
                {
                    _page.FlushChildPages();
                }
            }

            BindGrid();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if ( Page.IsValid )
            {
                using ( new Rock.Data.UnitOfWorkScope() )
                {
                    Rock.CMS.PageService pageService = new Rock.CMS.PageService();
                    Rock.CMS.Page page = pageService.Get( _page.Id );

                    int parentPage = Int32.Parse( ddlParentPage.SelectedValue );
                    if ( page.ParentPageId != parentPage )
                    {
                        if ( page.ParentPageId.HasValue )
                            Rock.Web.Cache.Page.Flush( page.ParentPageId.Value );

                        if ( parentPage != 0 )
                            Rock.Web.Cache.Page.Flush( parentPage );
                    }

                    page.Name = tbPageName.Text;
                    page.Title = tbPageTitle.Text;
                    if ( parentPage != 0 )
                        page.ParentPageId = parentPage;
                    else
                        page.ParentPageId = null;
                    page.Layout = ddlLayout.Text;
                    page.DisplayInNavWhen = ( Rock.CMS.DisplayInNavWhen )Enum.Parse( typeof( Rock.CMS.DisplayInNavWhen ), ddlMenuWhen.SelectedValue );
                    page.MenuDisplayDescription = cbMenuDescription.Checked;
                    page.MenuDisplayIcon = cbMenuIcon.Checked;
                    page.MenuDisplayChildPages = cbMenuChildPages.Checked;
                    page.RequiresEncryption = cbRequiresEncryption.Checked;
                    page.EnableViewState = cbRequiresEncryption.Checked;
                    page.IncludeAdminFooter = cbIncludeAdminFooter.Checked;
                    page.OutputCacheDuration = Int32.Parse( tbCacheDuration.Text );
                    page.Description = tbDescription.Text;

                    pageService.Save( page, CurrentPersonId );

                    Rock.Attribute.Helper.GetEditValues( phAttributes, _page );
                    _page.SaveAttributeValues( CurrentPersonId );

                    Rock.Web.Cache.Page.Flush( _page.Id );
                }

                string script = "window.parent.closeModal()";
                this.Page.ClientScript.RegisterStartupScript( this.GetType(), "close-modal", script, true );
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack && _page.Authorized("Configure", CurrentUser))
            {
                Rock.CMS.PageService pageService = new Rock.CMS.PageService();
                Rock.CMS.Page        page        = pageService.Get(_page.Id);

                rptProperties.DataSource = tabs;
                rptProperties.DataBind();

                LoadDropdowns();

                tbPageName.Text             = _page.Name;
                tbPageTitle.Text            = _page.Title;
                ddlParentPage.SelectedValue = _page.ParentPage != null?_page.ParentPage.Id.ToString() : "0";

                ddlLayout.Text               = _page.Layout;
                ddlMenuWhen.SelectedValue    = (( Int32 )_page.DisplayInNavWhen).ToString();
                cbMenuDescription.Checked    = _page.MenuDisplayDescription;
                cbMenuIcon.Checked           = _page.MenuDisplayIcon;
                cbMenuChildPages.Checked     = _page.MenuDisplayChildPages;
                cbRequiresEncryption.Checked = _page.RequiresEncryption;
                cbEnableViewState.Checked    = _page.EnableViewstate;
                cbIncludeAdminFooter.Checked = _page.IncludeAdminFooter;
                tbCacheDuration.Text         = _page.OutputCacheDuration.ToString();
                tbDescription.Text           = _page.Description;
                tbPageRoute.Text             = string.Join(",", page.PageRoutes.Select(route => route.Route).ToArray());
            }

            base.OnLoad(e);

            if (Page.IsPostBack)
            {
                Rock.Attribute.Helper.SetErrorIndicators(phAttributes, _page);
            }
        }
Beispiel #9
0
        public Rock.CMS.DTO.Page Get(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                Rock.CMS.Page        Page        = PageService.Get(int.Parse(id));
                if (Page.Authorized("View", currentUser))
                {
                    return(Page.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #10
0
        public void ApiUpdatePage(string id, string apiKey, Rock.CMS.DTO.Page Page)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.PageService PageService  = new Rock.CMS.PageService();
                    Rock.CMS.Page        existingPage = PageService.Get(int.Parse(id));
                    if (existingPage.Authorized("Edit", user))
                    {
                        uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page);

                        if (existingPage.IsValid)
                        {
                            PageService.Save(existingPage, user.PersonId);
                        }
                        else
                        {
                            throw new WebFaultException <string>(existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                        }
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #11
0
        public void ApiDeletePage( string id, string apiKey )
        {
            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                    Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
                    if ( Page.Authorized( "Edit", user ) )
                    {
                        PageService.Delete( Page, user.PersonId );
                        PageService.Save( Page, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Beispiel #12
0
        public void UpdatePage( string id, Rock.CMS.DTO.Page Page )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                Rock.CMS.Page existingPage = PageService.Get( int.Parse( id ) );
                if ( existingPage.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page);

                    if (existingPage.IsValid)
                        PageService.Save( existingPage, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
            }
        }
Beispiel #13
0
        public Rock.CMS.DTO.Page Get( string id )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
                if ( Page.Authorized( "View", currentUser ) )
                    return Page.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden );
            }
        }
Beispiel #14
0
        public void DeletePage( string id )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
                if ( Page.Authorized( "Edit", currentUser ) )
                {
                    PageService.Delete( Page, currentUser.PersonId );
                    PageService.Save( Page, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
            }
        }
Beispiel #15
0
        public void ApiUpdatePage( string id, string apiKey, Rock.CMS.DTO.Page Page )
        {
            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                    Rock.CMS.Page existingPage = PageService.Get( int.Parse( id ) );
                    if ( existingPage.Authorized( "Edit", user ) )
                    {
                        uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page);

                        if (existingPage.IsValid)
                            PageService.Save( existingPage, user.PersonId );
                        else
                            throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Beispiel #16
0
        public Rock.CMS.DTO.Page ApiGet( string id, string apiKey )
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.PageService PageService = new Rock.CMS.PageService();
                    Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
                    if ( Page.Authorized( "View", user ) )
                        return Page.DataTransferObject;
                    else
                        throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
        void masterPage_OnSave(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (new Rock.Data.UnitOfWorkScope())
                {
                    Rock.CMS.PageService      pageService  = new Rock.CMS.PageService();
                    Rock.CMS.Page             page         = pageService.Get(_page.Id);
                    Rock.CMS.PageRouteService routeService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute        pr;

                    int parentPage = Int32.Parse(ddlParentPage.SelectedValue);
                    if (page.ParentPageId != parentPage)
                    {
                        if (page.ParentPageId.HasValue)
                        {
                            Rock.Web.Cache.Page.Flush(page.ParentPageId.Value);
                        }

                        if (parentPage != 0)
                        {
                            Rock.Web.Cache.Page.Flush(parentPage);
                        }

                        foreach (var route in page.PageRoutes)
                        {
                            routeService.Delete(route, CurrentPersonId);
                        }
                        page.PageRoutes.Clear();
                    }

                    page.Name  = tbPageName.Text;
                    page.Title = tbPageTitle.Text;
                    if (parentPage != 0)
                    {
                        page.ParentPageId = parentPage;
                    }
                    else
                    {
                        page.ParentPageId = null;
                    }
                    page.Layout                 = ddlLayout.Text;
                    page.DisplayInNavWhen       = (Rock.CMS.DisplayInNavWhen)Enum.Parse(typeof(Rock.CMS.DisplayInNavWhen), ddlMenuWhen.SelectedValue);
                    page.MenuDisplayDescription = cbMenuDescription.Checked;
                    page.MenuDisplayIcon        = cbMenuIcon.Checked;
                    page.MenuDisplayChildPages  = cbMenuChildPages.Checked;
                    page.RequiresEncryption     = cbRequiresEncryption.Checked;
                    page.EnableViewState        = cbEnableViewState.Checked;
                    page.IncludeAdminFooter     = cbIncludeAdminFooter.Checked;
                    page.OutputCacheDuration    = Int32.Parse(tbCacheDuration.Text);
                    page.Description            = tbDescription.Text;

                    foreach (string route in tbPageRoute.Text.SplitDelimitedValues())
                    {
                        pr       = new Rock.CMS.PageRoute();
                        pr.Route = route;
                        pr.Guid  = Guid.NewGuid();
                        page.PageRoutes.Add(pr);
                    }

                    pageService.Save(page, CurrentPersonId);

                    Rock.Attribute.Helper.GetEditValues(phAttributes, _page);
                    _page.SaveAttributeValues(CurrentPersonId);

                    Rock.Web.Cache.Page.Flush(_page.Id);
                }

                string script = "window.parent.closeModal()";
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", script, true);
            }
        }