public void ApiCreateFieldType(string apiKey, Rock.Core.DTO.FieldType FieldType) { 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 existingFieldType = new Rock.Core.FieldType(); FieldTypeService.Add(existingFieldType, user.PersonId); uow.objectContext.Entry(existingFieldType).CurrentValues.SetValues(FieldType); if (existingFieldType.IsValid) { FieldTypeService.Save(existingFieldType, user.PersonId); } else { throw new WebFaultException <string>(existingFieldType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void CreateFieldType(Rock.Core.DTO.FieldType FieldType) { 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 existingFieldType = new Rock.Core.FieldType(); FieldTypeService.Add(existingFieldType, currentUser.PersonId); uow.objectContext.Entry(existingFieldType).CurrentValues.SetValues(FieldType); if (existingFieldType.IsValid) { FieldTypeService.Save(existingFieldType, currentUser.PersonId); } else { throw new WebFaultException <string>(existingFieldType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } }