/// <summary> /// Handles the Delete event of the gBlockTypes control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gBlockTypes_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); BlockTypeService blockTypeService = new BlockTypeService( rockContext ); BlockType blockType = blockTypeService.Get( e.RowKeyId ); if ( blockType != null ) { string errorMessage; if ( !blockTypeService.CanDelete( blockType, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } blockTypeService.Delete( blockType ); rockContext.SaveChanges(); Rock.Web.Cache.BlockTypeCache.Flush( blockType.Id ); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gBlockTypes control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gBlockTypes_Delete( object sender, RowEventArgs e ) { RockTransactionScope.WrapTransaction( () => { BlockTypeService blockTypeService = new BlockTypeService(); BlockType blockType = blockTypeService.Get( (int)e.RowKeyValue ); if ( blockType != null ) { string errorMessage; if ( !blockTypeService.CanDelete( blockType, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } blockTypeService.Delete( blockType, CurrentPersonId ); blockTypeService.Save( blockType, CurrentPersonId ); Rock.Web.Cache.BlockTypeCache.Flush( blockType.Id ); } } ); BindGrid(); }