/// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            WorkflowTrigger        WorkflowTrigger;
            var                    rockContext            = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService(rockContext);
            AttributeService       attributeService       = new AttributeService(rockContext);

            int WorkflowTriggerId = int.Parse(hfWorkflowTriggerId.Value);

            if (WorkflowTriggerId == 0)
            {
                WorkflowTrigger = new WorkflowTrigger();
                WorkflowTriggerService.Add(WorkflowTrigger);
            }
            else
            {
                WorkflowTrigger = WorkflowTriggerService.Get(WorkflowTriggerId);
            }

            WorkflowTrigger.EntityTypeId = ddlEntityType.SelectedValueAsInt().Value;
            WorkflowTrigger.EntityTypeQualifierColumn = ddlQualifierColumn.SelectedValue;
            WorkflowTrigger.EntityTypeQualifierValue  = tbQualifierValue.Text;
            WorkflowTrigger.WorkflowTypeId            = ddlWorkflowType.SelectedValueAsInt().Value;
            WorkflowTrigger.WorkflowTriggerType       = (WorkflowTriggerType)System.Enum.Parse(typeof(WorkflowTriggerType), rblTriggerType.SelectedValue);
            WorkflowTrigger.IsActive = cbIsActive.Checked;
            if (string.IsNullOrWhiteSpace(tbWorkflowName.Text))
            {
                WorkflowTrigger.WorkflowName = null;
            }
            else
            {
                WorkflowTrigger.WorkflowName = tbWorkflowName.Text;
            }

            if (!WorkflowTrigger.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            Rock.Workflow.TriggerCache.Refresh();

            NavigateToParentPage();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            WorkflowTrigger        workflowTrigger;
            var                    rockContext            = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService(rockContext);
            AttributeService       attributeService       = new AttributeService(rockContext);
            bool                   usePreviousValue       = false;

            int WorkflowTriggerId = int.Parse(hfWorkflowTriggerId.Value);

            if (WorkflowTriggerId == 0)
            {
                workflowTrigger = new WorkflowTrigger();
                WorkflowTriggerService.Add(workflowTrigger);
            }
            else
            {
                workflowTrigger = WorkflowTriggerService.Get(WorkflowTriggerId);
            }

            workflowTrigger.WorkflowTypeId      = ddlWorkflowType.SelectedValueAsInt().Value;
            workflowTrigger.WorkflowTriggerType = (WorkflowTriggerType)System.Enum.Parse(typeof(WorkflowTriggerType), rblTriggerType.SelectedValue);

            workflowTrigger.EntityTypeId = ddlEntityType.SelectedValueAsInt().Value;
            workflowTrigger.EntityTypeQualifierColumn = ddlQualifierColumn.SelectedValue;

            //
            // If the trigger type is PreSave, PostSave or ImmediatePostSave then we have
            // a previous value option.
            //
            if (workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave ||
                workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PostSave ||
                workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave)
            {
                usePreviousValue = true;
            }

            // If the trigger type is PreSave and the tbQualifierValue does not exist,
            // use the previous and alt qualifier value
            if (usePreviousValue)
            {
                if (!string.IsNullOrEmpty(tbQualifierValue.Text))
                {
                    // in this case, use the same value as the previous and current qualifier value
                    workflowTrigger.EntityTypeQualifierValue         = tbQualifierValue.Text;
                    workflowTrigger.EntityTypeQualifierValuePrevious = tbQualifierValue.Text;
                }
                else
                {
                    workflowTrigger.EntityTypeQualifierValue         = tbQualifierValueAlt.Text;
                    workflowTrigger.EntityTypeQualifierValuePrevious = tbPreviousQualifierValue.Text;
                }
            }
            else
            {
                // use the regular qualifier and clear the previous value qualifier since it does not apply.
                workflowTrigger.EntityTypeQualifierValue         = tbQualifierValue.Text;
                workflowTrigger.EntityTypeQualifierValuePrevious = string.Empty;
            }

            workflowTrigger.IsActive = cbIsActive.Checked;
            if (string.IsNullOrWhiteSpace(tbWorkflowName.Text))
            {
                workflowTrigger.WorkflowName = null;
            }
            else
            {
                workflowTrigger.WorkflowName = tbWorkflowName.Text;
            }

            if (!workflowTrigger.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            WorkflowTriggersCache.Remove();

            NavigateToParentPage();
        }