/// <summary> /// Handles the Click event of the DeleteConnectionOpportunity control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param> protected void DeleteConnectionOpportunity_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { using (RockContext rockContext = new RockContext()) { ConnectionOpportunityService connectionOpportunityService = new ConnectionOpportunityService(rockContext); ConnectionOpportunity connectionOpportunity = connectionOpportunityService.Get(e.RowKeyId); if (connectionOpportunity != null) { if (_canEdit || connectionOpportunity.IsAuthorized(Authorization.EDIT, CurrentPerson)) { string errorMessage; if (!connectionOpportunityService.CanDelete(connectionOpportunity, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } int connectionTypeId = connectionOpportunity.ConnectionTypeId; connectionOpportunityService.Delete(connectionOpportunity); rockContext.SaveChanges(); ConnectionWorkflowService.RemoveCachedTriggers(); } else { mdGridWarning.Show("You are not authorized to delete this calendar item", ModalAlertType.Warning); } } } BindConnectionOpportunitiesGrid(); }
/// <summary> /// Handles the Delete event of the gConnectionType 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 gConnectionType_Delete(object sender, RowEventArgs e) { using (var rockContext = new RockContext()) { ConnectionWorkflowService connectionWorkflowService = new ConnectionWorkflowService(rockContext); ConnectionTypeService connectionTypeService = new ConnectionTypeService(rockContext); AuthService authService = new AuthService(rockContext); ConnectionType connectionType = connectionTypeService.Get(e.RowKeyId); if (connectionType != null) { if (!connectionType.IsAuthorized(Authorization.ADMINISTRATE, this.CurrentPerson)) { mdGridWarning.Show("You are not authorized to delete this connection type.", ModalAlertType.Information); return; } // var connectionOppotunityies = new Service<ConnectionOpportunity>( rockContext ).Queryable().All( a => a.ConnectionTypeId == connectionType.Id ); var connectionOpportunities = connectionType.ConnectionOpportunities.ToList(); ConnectionOpportunityService connectionOpportunityService = new ConnectionOpportunityService(rockContext); ConnectionRequestActivityService connectionRequestActivityService = new ConnectionRequestActivityService(rockContext); foreach (var connectionOpportunity in connectionOpportunities) { var connectionRequestActivities = new Service <ConnectionRequestActivity>(rockContext).Queryable().Where(a => a.ConnectionOpportunityId == connectionOpportunity.Id).ToList(); foreach (var connectionRequestActivity in connectionRequestActivities) { connectionRequestActivityService.Delete(connectionRequestActivity); } rockContext.SaveChanges(); string errorMessageConnectionOpportunity; if (!connectionOpportunityService.CanDelete(connectionOpportunity, out errorMessageConnectionOpportunity)) { mdGridWarning.Show(errorMessageConnectionOpportunity, ModalAlertType.Information); return; } connectionOpportunityService.Delete(connectionOpportunity); } rockContext.SaveChanges(); string errorMessage; if (!connectionTypeService.CanDelete(connectionType, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } connectionTypeService.Delete(connectionType); rockContext.SaveChanges(); ConnectionWorkflowService.RemoveCachedTriggers(); } } BindGrid(); }