Exemple #1
0
        /// <summary>
        /// Updates the workflow.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="recommendation">The recommendation.</param>
        /// <param name="reportLink">The report link.</param>
        /// <param name="reportStatus">The report status.</param>
        /// <param name="rockContext">The rock context.</param>
        private static void UpdateWorkflow(int id, string recommendation, string documentId, string reportStatus, RockContext rockContext)
        {
            var workflowService = new WorkflowService(rockContext);
            var workflow        = new WorkflowService(rockContext).Get(id);

            if (workflow != null && workflow.IsActive)
            {
                workflow.LoadAttributes();
                if (workflow.Attributes.ContainsKey("ReportStatus"))
                {
                    if (workflow.GetAttributeValue("ReportStatus").IsNotNullOrWhiteSpace() && reportStatus.IsNullOrWhiteSpace())
                    {
                        // Don't override current values if Webhook is older than current values
                        return;
                    }
                }

                if (workflow.Attributes.ContainsKey("Report"))
                {
                    if (workflow.GetAttributeValue("Report").IsNotNullOrWhiteSpace() && documentId.IsNullOrWhiteSpace())
                    {
                        // Don't override current values if Webhook is older than current values
                        return;
                    }
                }

                // Save the recommendation
                if (!string.IsNullOrWhiteSpace(recommendation))
                {
                    if (SaveAttributeValue(workflow, "ReportRecommendation", recommendation,
                                           FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext,
                                           new Dictionary <string, string> {
                        { "ispassword", "false" }
                    }))
                    {
                    }
                }
                // Save the report link
                if (documentId.IsNotNullOrWhiteSpace())
                {
                    int entityTypeId = EntityTypeCache.Get(typeof(Checkr)).Id;
                    if (SaveAttributeValue(workflow, "Report", $"{entityTypeId},{documentId}",
                                           FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext,
                                           new Dictionary <string, string> {
                        { "ispassword", "false" }
                    }))
                    {
                    }
                }

                if (!string.IsNullOrWhiteSpace(reportStatus))
                {
                    // Save the status
                    if (SaveAttributeValue(workflow, "ReportStatus", reportStatus,
                                           FieldTypeCache.Get(Rock.SystemGuid.FieldType.SINGLE_SELECT.AsGuid()), rockContext,
                                           new Dictionary <string, string> {
                        { "fieldtype", "ddl" }, { "values", "Pass,Fail,Review" }
                    }))
                    {
                    }
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    workflow.SaveAttributeValues(rockContext);
                    foreach (var activity in workflow.Activities)
                    {
                        activity.SaveAttributeValues(rockContext);
                    }
                });
            }

            rockContext.SaveChanges();

            List <string> workflowErrors;

            workflowService.Process(workflow, out workflowErrors);
        }