public void UpdateAttribute(string id, Rock.Core.DTO.Attribute Attribute) { 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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = AttributeService.Get(int.Parse(id)); if (existingAttribute.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) { AttributeService.Save(existingAttribute, currentUser.PersonId); } else { throw new WebFaultException <string>(existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiDeleteAttribute(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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute Attribute = AttributeService.Get(int.Parse(id)); if (Attribute.Authorized("Edit", user)) { AttributeService.Delete(Attribute, user.PersonId); AttributeService.Save(Attribute, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteAttribute(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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute Attribute = AttributeService.Get(int.Parse(id)); if (Attribute.Authorized("Edit", currentUser)) { AttributeService.Delete(Attribute, currentUser.PersonId); AttributeService.Save(Attribute, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateAttribute(string apiKey, Rock.Core.DTO.Attribute Attribute) { 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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = new Rock.Core.Attribute(); AttributeService.Add(existingAttribute, user.PersonId); uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) { AttributeService.Save(existingAttribute, user.PersonId); } else { throw new WebFaultException <string>(existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiDeleteAttribute( 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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute Attribute = AttributeService.Get( int.Parse( id ) ); if ( Attribute.Authorized( "Edit", user ) ) { AttributeService.Delete( Attribute, user.PersonId ); AttributeService.Save( Attribute, user.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void ApiCreateAttribute( string apiKey, Rock.Core.DTO.Attribute Attribute ) { 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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = new Rock.Core.Attribute(); AttributeService.Add( existingAttribute, user.PersonId ); uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) AttributeService.Save( existingAttribute, user.PersonId ); else throw new WebFaultException<string>( existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void UpdateAttribute( string id, Rock.Core.DTO.Attribute Attribute ) { 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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = AttributeService.Get( int.Parse( id ) ); if ( existingAttribute.Authorized( "Edit", currentUser ) ) { uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) AttributeService.Save( existingAttribute, currentUser.PersonId ); else throw new WebFaultException<string>( existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden ); } }
public void DeleteAttribute( 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.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute Attribute = AttributeService.Get( int.Parse( id ) ); if ( Attribute.Authorized( "Edit", currentUser ) ) { AttributeService.Delete( Attribute, currentUser.PersonId ); AttributeService.Save( Attribute, currentUser.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden ); } }