public void UpdateHtmlContent(string id, Rock.CMS.DTO.HtmlContent HtmlContent) { 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.HtmlContentService HtmlContentService = new Rock.CMS.HtmlContentService(); Rock.CMS.HtmlContent existingHtmlContent = HtmlContentService.Get(int.Parse(id)); if (existingHtmlContent.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingHtmlContent).CurrentValues.SetValues(HtmlContent); if (existingHtmlContent.IsValid) { HtmlContentService.Save(existingHtmlContent, currentUser.PersonId); } else { throw new WebFaultException <string>(existingHtmlContent.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this HtmlContent", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.CMS.DTO.HtmlContent 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.HtmlContentService HtmlContentService = new Rock.CMS.HtmlContentService(); Rock.CMS.HtmlContent HtmlContent = HtmlContentService.Get(int.Parse(id)); if (HtmlContent.Authorized("View", user)) { return(HtmlContent.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this HtmlContent", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiDeleteHtmlContent(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.HtmlContentService HtmlContentService = new Rock.CMS.HtmlContentService(); Rock.CMS.HtmlContent HtmlContent = HtmlContentService.Get(int.Parse(id)); if (HtmlContent.Authorized("Edit", user)) { HtmlContentService.Delete(HtmlContent, user.PersonId); HtmlContentService.Save(HtmlContent, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this HtmlContent", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteHtmlContent(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.HtmlContentService HtmlContentService = new Rock.CMS.HtmlContentService(); Rock.CMS.HtmlContent HtmlContent = HtmlContentService.Get(int.Parse(id)); if (HtmlContent.Authorized("Edit", currentUser)) { HtmlContentService.Delete(HtmlContent, currentUser.PersonId); HtmlContentService.Save(HtmlContent, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this HtmlContent", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.CMS.DTO.HtmlContent 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.HtmlContentService HtmlContentService = new Rock.CMS.HtmlContentService(); Rock.CMS.HtmlContent HtmlContent = HtmlContentService.Get(int.Parse(id)); if (HtmlContent.Authorized("View", currentUser)) { return(HtmlContent.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this HtmlContent", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiUpdateHtmlContent(string id, string apiKey, Rock.CMS.DTO.HtmlContent HtmlContent) { 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.HtmlContentService HtmlContentService = new Rock.CMS.HtmlContentService(); Rock.CMS.HtmlContent existingHtmlContent = HtmlContentService.Get(int.Parse(id)); if (existingHtmlContent.Authorized("Edit", user)) { uow.objectContext.Entry(existingHtmlContent).CurrentValues.SetValues(HtmlContent); if (existingHtmlContent.IsValid) { HtmlContentService.Save(existingHtmlContent, user.PersonId); } else { throw new WebFaultException <string>(existingHtmlContent.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this HtmlContent", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }