示例#1
0
        public void CreatePage(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 = new Rock.CMS.Page();
                PageService.Add(existingPage, currentUser.PersonId);
                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);
                }
            }
        }
示例#2
0
        public void ApiCreatePage(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 = new Rock.CMS.Page();
                    PageService.Add(existingPage, user.PersonId);
                    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>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#3
0
        public void ApiCreatePage( 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 = new Rock.CMS.Page();
                    PageService.Add( existingPage, user.PersonId );
                    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>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
示例#4
0
        public void CreatePage( 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 = new Rock.CMS.Page();
                PageService.Add( existingPage, currentUser.PersonId );
                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 );
            }
        }
示例#5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Rock.CMS.Page page;

            int pageId = 0;

            if (!Int32.TryParse(hfPageId.Value, out pageId))
            {
                pageId = 0;
            }

            if (pageId == 0)
            {
                page = new Rock.CMS.Page();

                if (_page != null)
                {
                    page.ParentPageId = _page.Id;
                    page.SiteId       = _page.Site.Id;
                }
                else
                {
                    page.ParentPageId = null;
                    page.SiteId       = PageInstance.Site.Id;
                }

                page.Title              = tbPageName.Text;
                page.EnableViewState    = true;
                page.IncludeAdminFooter = true;

                Rock.CMS.Page lastPage =
                    pageService.GetByParentPageId(_page.Id).
                    OrderByDescending(b => b.Order).FirstOrDefault();

                if (lastPage != null)
                {
                    page.Order = lastPage.Order + 1;
                }
                else
                {
                    page.Order = 0;
                }

                pageService.Add(page, CurrentPersonId);
            }
            else
            {
                page = pageService.Get(pageId);
            }

            page.Layout = ddlLayout.Text;
            page.Name   = tbPageName.Text;

            pageService.Save(page, CurrentPersonId);

            if (_page != null)
            {
                Rock.Security.Authorization.CopyAuthorization(_page, page, CurrentPersonId);
                _page.FlushChildPages();
            }

            BindGrid();

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