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