/// <summary>
        /// Handles the Delete event of the gWorkflows 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 gWorkflows_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            WorkflowService workflowService = new WorkflowService( rockContext );
            Workflow workflow = workflowService.Get( (int)e.RowKeyValue );
            if ( workflow != null )
            {
                string errorMessage;
                if ( !workflowService.CanDelete( workflow, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                workflowService.Delete( workflow );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
        {
            errorMessages = new List<string>();

            var workflow = action.Activity.Workflow;
            if ( workflow.Id >= 0 )
            {
                // Create a new RockContext so that any previous updates are ignored and
                // workflow can be sucessfully deleted
                var newRockContext = new RockContext();
                var workflowService = new WorkflowService( newRockContext );
                var workflowToDelete = workflowService.Get( workflow.Id );
                if ( workflowToDelete != null )
                {
                    workflowService.Delete( workflowToDelete );
                    newRockContext.SaveChanges();
                }
            }

            workflow.Id = 0;
            workflow.IsPersisted = false;

            return true;
        }
Exemple #3
0
        /// <summary>
        /// Handles the Delete event of the gWorkflows 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 gWorkflows_Delete( object sender, RowEventArgs e )
        {
            RockTransactionScope.WrapTransaction( () =>
            {
                WorkflowService workflowService = new WorkflowService();
                Workflow workflow = workflowService.Get( (int)e.RowKeyValue );
                if ( workflow != null )
                {
                    string errorMessage;
                    if ( !workflowService.CanDelete( workflow, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    workflowService.Delete( workflow, CurrentPersonId );
                    workflowService.Save( workflow, CurrentPersonId );
                }
            } );

            BindGrid();
        }