public void DeleteBlock(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.CMS.BlockService BlockService = new Rock.CMS.BlockService(); Rock.CMS.Block Block = BlockService.Get(int.Parse(id)); if (Block.Authorized("Edit", currentUser)) { BlockService.Delete(Block, currentUser.PersonId); BlockService.Save(Block, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiDeleteBlock(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.CMS.BlockService BlockService = new Rock.CMS.BlockService(); Rock.CMS.Block Block = BlockService.Get(int.Parse(id)); if (Block.Authorized("Edit", user)) { BlockService.Delete(Block, user.PersonId); BlockService.Save(Block, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
protected void rGrid_Delete(object sender, RowEventArgs e) { Rock.CMS.Block block = _blockService.Get(( int )rGrid.DataKeys[e.RowIndex]["id"]); if (BlockInstance != null) { _blockService.Delete(block, CurrentPersonId); _blockService.Save(block, CurrentPersonId); Rock.Web.Cache.Block.Flush(block.Id); } BindGrid(); }
public void ApiDeleteBlock( 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.CMS.BlockService BlockService = new Rock.CMS.BlockService(); Rock.CMS.Block Block = BlockService.Get( int.Parse( id ) ); if ( Block.Authorized( "Edit", user ) ) { BlockService.Delete( Block, user.PersonId ); BlockService.Save( Block, user.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void DeleteBlock( 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.CMS.BlockService BlockService = new Rock.CMS.BlockService(); Rock.CMS.Block Block = BlockService.Get( int.Parse( id ) ); if ( Block.Authorized( "Edit", currentUser ) ) { BlockService.Delete( Block, currentUser.PersonId ); BlockService.Save( Block, currentUser.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Block", System.Net.HttpStatusCode.Forbidden ); } }