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