protected void gRequests_Delete(object sender, RowEventArgs e) { using (RockContext rockContext = new RockContext()) { var service = new ConnectionRequestService(rockContext); var connectionRequest = service.Get(e.RowKeyId); if (connectionRequest != null) { string errorMessage; if (!service.CanDelete(connectionRequest, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } rockContext.WrapTransaction(() => { new ConnectionRequestActivityService(rockContext).DeleteRange(connectionRequest.ConnectionRequestActivities); service.Delete(connectionRequest); rockContext.SaveChanges(); }); } } BindGrid(); }
protected void gRequests_Delete( object sender, RowEventArgs e ) { using ( RockContext rockContext = new RockContext() ) { var service = new ConnectionRequestService( rockContext ); var connectionRequest = service.Get( e.RowKeyId ); if ( connectionRequest != null ) { string errorMessage; if ( !service.CanDelete( connectionRequest, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } rockContext.WrapTransaction( () => { new ConnectionRequestActivityService( rockContext ).DeleteRange( connectionRequest.ConnectionRequestActivities ); service.Delete( connectionRequest ); rockContext.SaveChanges(); } ); } } BindGrid(); }