Beispiel #1
0
        public static IWorkflowStepItem ToModel(this DbWorkflowStepItem item, IJsonHelper jsonHelper)
        {
            switch (item.ItemType)
            {
            case WorkflowStepItemType.SimpleQuestion:
                return(GetSimpleQuestion(item, jsonHelper));

            case WorkflowStepItemType.TextScenario:
                return(GetTextScenario(item, jsonHelper));

            default:
                throw new Exception(
                          string.Format("Workflow step item {0} does not have a valid type. Type: {1}",
                                        item.Code, item.ItemType));
            }
        }
Beispiel #2
0
        private static TextScenario GetTextScenario(DbWorkflowStepItem item, IJsonHelper jsonHelper)
        {
            Result <IEnumerable <Question> > result = jsonHelper.Deserialize <IEnumerable <Question> > (item.Content);

            if (result.IsFailure)
            {
                throw new Exception(string.Format("Could not deserialize TextScenario workflow step item content to IEnumerable<Question>. Code: {0}", item.Code));
            }

            return(new TextScenario {
                Id = item.Id,
                Code = item.Code,
                CultureCode = item.CultureCode,
                Questions = result.Value,
                LastModified = item.LastModified,
                DateCreated = item.DateCreated
            });
        }
Beispiel #3
0
        private static SimpleQuestion GetSimpleQuestion(DbWorkflowStepItem item, IJsonHelper jsonHelper)
        {
            Result <Question> result = jsonHelper.Deserialize <Question> (item.Content);

            if (result.IsFailure)
            {
                throw new Exception(string.Format("Could not deserialize SimpleQuestion workflow step item content to Question. Code: {0}", item.Code));
            }

            return(new SimpleQuestion {
                Id = item.Id,
                Code = item.Code,
                CultureCode = item.CultureCode,
                Question = result.Value,
                LastModified = item.LastModified,
                DateCreated = item.DateCreated
            });
        }
Beispiel #4
0
 private Maybe <IWorkflowStepItem> MaybeWorkflowStepItem(DbWorkflowStepItem workflowStepItem)
 {
     return(workflowStepItem != null
             ? new Maybe <IWorkflowStepItem>(workflowStepItem.ToModel(jsonHelper))
             : Maybe <IWorkflowStepItem> .Fail);
 }