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); } } }
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); } } }