/// <summary> /// Handles the Delete event of the gBenevolenceType 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 gBenevolenceType_Delete(object sender, RowEventArgs e) { using (var rockContext = new RockContext()) { rockContext.WrapTransaction(action: () => { var benevolenceWorkflowService = new BenevolenceWorkflowService(rockContext); var benevolenceTypeService = new BenevolenceTypeService(rockContext); var authService = new AuthService(rockContext); BenevolenceType benevolenceType = benevolenceTypeService.Get(e.RowKeyId); if (benevolenceType != null) { // Do not allow deletions if the person is not authorized if (!benevolenceType.IsAuthorized(Authorization.ADMINISTRATE, this.CurrentPerson)) { mdGridWarning.Show("You are not authorized to delete this Benevolence type.", ModalAlertType.Information); return; } // var benevolenceRequests = new Service<BenevolenceRequest>( rockContext ).Queryable().All( a => a.BenevolenceTypeId == BenevolenceType.Id ); var benevolenceRequests = benevolenceType.BenevolenceRequests.ToList(); var benevolenceRequestService = new BenevolenceRequestService(rockContext); string errorMessageBenevolenceRequest = string.Empty; foreach (var benvolenceRequest in benevolenceRequests) { if (!benevolenceRequestService.CanDelete(benvolenceRequest, out errorMessageBenevolenceRequest)) { mdGridWarning.Show(errorMessageBenevolenceRequest, ModalAlertType.Information); return; } benevolenceRequestService.Delete(benvolenceRequest); } // Save deleting the benevolence requests for the benevolence type id rockContext.SaveChanges(); string errorMessageBenevolenceType; if (!benevolenceTypeService.CanDelete(benevolenceType, out errorMessageBenevolenceType)) { mdGridWarning.Show(errorMessageBenevolenceType, ModalAlertType.Information); return; } benevolenceTypeService.Delete(benevolenceType); rockContext.SaveChanges(); // ToDo: benevolenceWorkflowService.RemoveCachedTriggers(); } }); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gList 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 dfBenevolenceRequest_Click(object sender, RowEventArgs e) { var rockContext = new RockContext(); BenevolenceRequestService service = new BenevolenceRequestService(rockContext); BenevolenceRequest benevolenceRequest = service.Get(e.RowKeyId); if (benevolenceRequest != null) { string errorMessage; if (!service.CanDelete(benevolenceRequest, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } service.Delete(benevolenceRequest); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the DeleteClick event of the gGrid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> private void gGrid_DeleteClick(object sender, RowEventArgs e) { var rockContext = new RockContext(); var benevolenceRequestService = new BenevolenceRequestService(rockContext); var benevolenceRequest = benevolenceRequestService.Get(e.RowKeyId); string errorMessage; if (benevolenceRequest == null) { return; } if (!benevolenceRequestService.CanDelete(benevolenceRequest, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } benevolenceRequestService.Delete(benevolenceRequest); rockContext.SaveChanges(); BindGrid(); }
/// <summary> /// Handles the Delete event of the gList 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 gList_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); BenevolenceRequestService service = new BenevolenceRequestService( rockContext ); BenevolenceRequest benevolenceRequest = service.Get( e.RowKeyId ); if ( benevolenceRequest != null ) { string errorMessage; if ( !service.CanDelete( benevolenceRequest, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } service.Delete( benevolenceRequest ); rockContext.SaveChanges(); } BindGrid(); }