Exemplo n.º 1
0
            /// <summary>
            /// Deletes any connection request workflows tied to this workflow.
            /// </summary>
            private void DeleteConnectionRequestWorkflows()
            {
                var connectionRequestWorkflowService = new ConnectionRequestWorkflowService(RockContext);
                var connectionRequestWorkflows       = connectionRequestWorkflowService.Queryable().Where(c => c.WorkflowId == this.Entity.Id);

                if (connectionRequestWorkflows.Any())
                {
                    RockContext.BulkDelete(connectionRequestWorkflows);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes any connection request workflows tied to this connection workflow.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        private void DeleteConnectionRequestWorkflows(Data.DbContext dbContext)
        {
            var rockContext = ( RockContext )dbContext;
            var connectionRequestWorkflowService = new ConnectionRequestWorkflowService(rockContext);
            var connectionRequestWorkflows       = connectionRequestWorkflowService.Queryable().Where(c => c.ConnectionWorkflowId == this.Id);

            if (connectionRequestWorkflows.Any())
            {
                dbContext.BulkDelete(connectionRequestWorkflows);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Pres the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, EntityState state)
        {
            if (state == EntityState.Deleted)
            {
                var rockContext = dbContext as RockContext;

                // manually clear any registrations using this workflow type
                foreach (var template in new RegistrationTemplateService(rockContext)
                         .Queryable()
                         .Where(r =>
                                r.RegistrationWorkflowTypeId.HasValue &&
                                r.RegistrationWorkflowTypeId.Value == this.Id))
                {
                    template.RegistrationWorkflowTypeId = null;
                }

                foreach (var instance in new RegistrationInstanceService(rockContext)
                         .Queryable()
                         .Where(r =>
                                r.RegistrationWorkflowTypeId.HasValue &&
                                r.RegistrationWorkflowTypeId.Value == this.Id))
                {
                    instance.RegistrationWorkflowTypeId = null;
                }

                /*
                 *  7/6/2020 - JH
                 *  The deletion of the Workflow object graph is accomplished by a combination of SQL cascade deletes and
                 *  PreSaveChanges() implementations.
                 *
                 *  When a WorkflowType is deleted, any child Workflows will be cascade-deleted. Most children of the deleted
                 *  Workflows will also be cascade-deleted, with the exception of any ConnectionRequestWorkflow records. Therefore,
                 *  we need to manually delete those here in order to prevent foreign key violations within the database.
                 *
                 *  Reason: GitHub Issue #4068
                 *  https://github.com/SparkDevNetwork/Rock/issues/4068#issuecomment-648908315
                 */
                var connectionRequestWorkflows = new ConnectionRequestWorkflowService(rockContext)
                                                 .Queryable()
                                                 .Where(c => c.Workflow.WorkflowTypeId == this.Id);

                if (connectionRequestWorkflows.Any())
                {
                    dbContext.BulkDelete(connectionRequestWorkflows);
                }
            }

            base.PreSaveChanges(dbContext, state);
        }