Пример #1
0
        public Rock.CMS.DTO.PageRoute 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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute        PageRoute        = PageRouteService.Get(int.Parse(id));
                    if (PageRoute.Authorized("View", user))
                    {
                        return(PageRoute.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this PageRoute", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #2
0
        public void UpdatePageRoute(string id, Rock.CMS.DTO.PageRoute PageRoute)
        {
            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.PageRouteService PageRouteService  = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute        existingPageRoute = PageRouteService.Get(int.Parse(id));
                if (existingPageRoute.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                    if (existingPageRoute.IsValid)
                    {
                        PageRouteService.Save(existingPageRoute, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #3
0
        public void DeletePageRoute(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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute        PageRoute        = PageRouteService.Get(int.Parse(id));
                if (PageRoute.Authorized("Edit", currentUser))
                {
                    PageRouteService.Delete(PageRoute, currentUser.PersonId);
                    PageRouteService.Save(PageRoute, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #4
0
        public void ApiCreatePageRoute(string apiKey, Rock.CMS.DTO.PageRoute PageRoute)
        {
            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.PageRouteService PageRouteService  = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute        existingPageRoute = new Rock.CMS.PageRoute();
                    PageRouteService.Add(existingPageRoute, user.PersonId);
                    uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                    if (existingPageRoute.IsValid)
                    {
                        PageRouteService.Save(existingPageRoute, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #5
0
        public Rock.CMS.DTO.PageRoute 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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute        PageRoute        = PageRouteService.Get(int.Parse(id));
                if (PageRoute.Authorized("View", currentUser))
                {
                    return(PageRoute.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this PageRoute", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #6
0
        public void ApiDeletePageRoute( 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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute PageRoute = PageRouteService.Get( int.Parse( id ) );
                    if ( PageRoute.Authorized( "Edit", user ) )
                    {
                        PageRouteService.Delete( PageRoute, user.PersonId );
                        PageRouteService.Save( PageRoute, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #7
0
        public void ApiCreatePageRoute( string apiKey, Rock.CMS.DTO.PageRoute PageRoute )
        {
            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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute existingPageRoute = new Rock.CMS.PageRoute();
                    PageRouteService.Add( existingPageRoute, user.PersonId );
                    uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                    if (existingPageRoute.IsValid)
                        PageRouteService.Save( existingPageRoute, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #8
0
        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 );
            }
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        public Rock.CMS.DTO.PageRoute 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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute PageRoute = PageRouteService.Get( int.Parse( id ) );
                    if ( PageRoute.Authorized( "View", user ) )
                        return PageRoute.DataTransferObject;
                    else
                        throw new WebFaultException<string>( "Not Authorized to View this PageRoute", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #11
0
        public void UpdatePageRoute( string id, Rock.CMS.DTO.PageRoute PageRoute )
        {
            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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute existingPageRoute = PageRouteService.Get( int.Parse( id ) );
                if ( existingPageRoute.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                    if (existingPageRoute.IsValid)
                        PageRouteService.Save( existingPageRoute, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #12
0
        public Rock.CMS.DTO.PageRoute 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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute PageRoute = PageRouteService.Get( int.Parse( id ) );
                if ( PageRoute.Authorized( "View", currentUser ) )
                    return PageRoute.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this PageRoute", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #13
0
        public void DeletePageRoute( 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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute PageRoute = PageRouteService.Get( int.Parse( id ) );
                if ( PageRoute.Authorized( "Edit", currentUser ) )
                {
                    PageRouteService.Delete( PageRoute, currentUser.PersonId );
                    PageRouteService.Save( PageRoute, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden );
            }
        }