public void UpdateFieldType(string id, 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 = FieldTypeService.Get(int.Parse(id)); if (existingFieldType.Authorized("Edit", currentUser)) { 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); } } else { throw new WebFaultException <string>("Not Authorized to Edit this FieldType", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.Core.DTO.FieldType 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.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType FieldType = FieldTypeService.Get(int.Parse(id)); if (FieldType.Authorized("View", user)) { return(FieldType.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View 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); } } }
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); } } }
/// <summary> /// Returns FieldType object from cache. If fieldType does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static FieldType Read(int id) { string cacheKey = FieldType.CacheKey(id); ObjectCache cache = MemoryCache.Default; FieldType fieldType = cache[cacheKey] as FieldType; if (fieldType != null) { return(fieldType); } else { Rock.Core.FieldTypeService fieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType fieldTypeModel = fieldTypeService.Get(id); if (fieldTypeModel != null) { fieldType = new FieldType(); fieldType.Id = fieldTypeModel.Id; fieldType.Name = fieldTypeModel.Name; fieldType.Description = fieldTypeModel.Description; fieldType.Field = Rock.FieldTypes.FieldHelper.InstantiateFieldType(fieldTypeModel.Assembly, fieldTypeModel.Class); cache.Set(cacheKey, fieldType, new CacheItemPolicy()); return(fieldType); } else { return(null); } } }
public Rock.Core.DTO.FieldType 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.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType FieldType = FieldTypeService.Get(int.Parse(id)); if (FieldType.Authorized("View", currentUser)) { return(FieldType.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this FieldType", System.Net.HttpStatusCode.Forbidden); } } }