Beispiel #1
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();
        }
Beispiel #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)
        {
            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();
        }
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(Message message)
        {
            while (message.WorkflowIds.Any())
            {
                using (var rockContext = new RockContext())
                {
                    var workflowIdSet = message.WorkflowIds.Take(100).ToList();
                    message.WorkflowIds = message.WorkflowIds.Skip(100).ToList();

                    var workflowService = new WorkflowService(rockContext);

                    var qry = workflowService.GetByIds(workflowIdSet);

                    foreach (var workflow in qry)
                    {
                        workflowService.Delete(workflow);
                    }

                    rockContext.SaveChanges();
                }
            }
        }
        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);
        }