Exemplo n.º 1
0
        /// <summary>
        /// Cleans up completed workflows.
        /// </summary>
        private int CleanUpWorkflows(JobDataMap dataMap)
        {
            int totalRowsDeleted = 0;
            var workflowContext  = new RockContext();
            var workflowService  = new WorkflowService(workflowContext);

            var completedWorkflows = workflowService.Queryable()
                                     .Where(w => w.WorkflowType.CompletedWorkflowRetentionPeriod.HasValue && w.Status.Equals("Completed"))
                                     .ToList();

            foreach (var workflow in completedWorkflows)
            {
                var retentionPeriod = workflow.WorkflowType.CompletedWorkflowRetentionPeriod;
                if (retentionPeriod.HasValue && workflow.ModifiedDateTime < RockDateTime.Now.AddDays(-1 * (int)retentionPeriod))
                {
                    string errorMessage;
                    if (workflowService.CanDelete(workflow, out errorMessage))
                    {
                        workflowService.Delete(workflow);
                        workflowContext.SaveChanges();
                        totalRowsDeleted++;
                    }
                }
            }

            return(totalRowsDeleted);
        }
Exemplo n.º 2
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)
        {
            var             rockContext     = new RockContext();
            WorkflowService workflowService = new WorkflowService(rockContext);
            Workflow        workflow        = workflowService.Get(e.RowKeyId);

            if (workflow != null)
            {
                string errorMessage;
                if (!workflowService.CanDelete(workflow, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

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

            BindGrid();
        }
Exemplo n.º 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();
        }
        private bool CanDelete(int id)
        {
            RockContext rockContext     = new RockContext();
            var         workflowService = new WorkflowService(rockContext);
            var         workflow        = workflowService.Get(id);
            string      errorMessage;

            if (workflow == null)
            {
                ShowAlert("This item could not be found", ModalAlertType.Information);
                return(false);
            }

            if (!workflowService.CanDelete(workflow, out errorMessage))
            {
                ShowAlert(errorMessage, ModalAlertType.Warning);
                return(false);
            }

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