Example #1
0
        /// <summary>
        /// Gets the step type.
        /// </summary>
        /// <param name="rockContext"></param>
        /// <param name="action">The action.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        private StepType GetStepType(RockContext rockContext, WorkflowAction action, out string errorMessage)
        {
            errorMessage = string.Empty;
            var      stepTypeIncludes = "StepProgram.StepStatuses";
            var      stepTypeService  = new StepTypeService(rockContext);
            StepType stepType         = null;
            var      stepTypeValue    = GetLavaAttributeValue(action, AttributeKey.StepProgramStepType);

            // Check if the value is a guid. This method works for stepProgram|stepType or simply just step type guids
            StepProgramStepTypeFieldType.ParseDelimitedGuids(stepTypeValue, out var unused1, out var stepTypeGuid);

            if (stepTypeGuid.HasValue)
            {
                stepType = stepTypeService.Queryable(stepTypeIncludes).AsNoTracking().FirstOrDefault(st => st.Guid == stepTypeGuid.Value);

                if (stepType == null)
                {
                    errorMessage = $"The step type with the guid '{stepTypeGuid.Value}' was not found";
                    return(null);
                }
            }

            // Try to get a step type with a step type id
            if (stepType == null)
            {
                var stepTypeId = stepTypeValue.AsIntegerOrNull();

                if (!stepTypeId.HasValue)
                {
                    errorMessage = "The step type identifier is required but was missing";
                    return(null);
                }

                stepType = stepTypeService.Queryable(stepTypeIncludes).AsNoTracking().FirstOrDefault(st => st.Id == stepTypeId.Value);

                if (stepType == null)
                {
                    errorMessage = $"The step type with the id '{stepTypeId.Value}' was not found";
                    return(null);
                }
            }

            if (stepType.StepProgram == null)
            {
                errorMessage = $"The step type '{stepType.Name}' program is missing";
                return(null);
            }

            if (stepType.StepProgram.StepStatuses == null || !stepType.StepProgram.StepStatuses.Any())
            {
                errorMessage = $"The step program '{stepType.StepProgram.Name}' does not have any statuses";
                return(null);
            }

            return(stepType);
        }
Example #2
0
        /// <summary>
        /// Gets the step program unique identifier from block attribute.
        /// </summary>
        /// <returns></returns>
        private Guid?GetStepProgramGuidFromBlockAttribute()
        {
            var attributeValue = GetAttributeValue(AttributeKey.StepProgramStepType);

            Guid?stepProgramGuid;
            Guid?stepTypeGuid;

            StepProgramStepTypeFieldType.ParseDelimitedGuids(attributeValue, out stepProgramGuid, out stepTypeGuid);

            return(stepProgramGuid);
        }