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 void ApiCreateHtmlContent(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 = new Rock.CMS.HtmlContent(); HtmlContentService.Add(existingHtmlContent, user.PersonId); 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>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }