public void ApiDeleteFieldType(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.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType FieldType = FieldTypeService.Get(int.Parse(id)); if (FieldType.Authorized("Edit", user)) { FieldTypeService.Delete(FieldType, user.PersonId); FieldTypeService.Save(FieldType, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this FieldType", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteFieldType(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.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType FieldType = FieldTypeService.Get(int.Parse(id)); if (FieldType.Authorized("Edit", currentUser)) { FieldTypeService.Delete(FieldType, currentUser.PersonId); FieldTypeService.Save(FieldType, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this FieldType", System.Net.HttpStatusCode.Forbidden); } } }