/// <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();
        }
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnDeleteConfirm_Click( object sender, EventArgs 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( int.Parse( hfConnectionTypeId.Value ) );

                if ( connectionType != null )
                {
                    if ( !connectionType.IsAuthorized( Authorization.ADMINISTRATE, this.CurrentPerson ) )
                    {
                        mdDeleteWarning.Show( "You are not authorized to delete this connection type.", ModalAlertType.Information );
                        return;
                    }

                    string errorMessage;
                    if ( !connectionTypeService.CanDelete( connectionType, out errorMessage ) )
                    {
                        mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    connectionTypeService.Delete( connectionType );
                    rockContext.SaveChanges();

                    ConnectionWorkflowService.FlushCachedTriggers();
                }
            }

            NavigateToParentPage();
        }