public async Task <PersonalizedPlanViewModel> MapViewModel(UnprocessedPersonalizedPlan personalizedPlanStepsInScope) { var actionPlan = new PersonalizedPlanViewModel(); foreach (var unprocessedTopic in personalizedPlanStepsInScope.UnprocessedTopics) { var resourceDetails = new List <Resource>(); var resourceIDs = unprocessedTopic.UnprocessedSteps.SelectMany(x => x.ResourceIds); if (resourceIDs != null || resourceIDs.Any()) { var resourceValues = resourceIDs.Select(x => x.ToString()).Distinct().ToList(); var resourceData = await dynamicQueries.FindItemsWhereInClauseAsync(cosmosDbSettings.ResourcesCollectionId, Constants.Id, resourceValues); resourceDetails = JsonUtilities.DeserializeDynamicObject <List <Resource> >(resourceData); } var topic = await topicsResourcesBusinessLogic.GetTopic(unprocessedTopic.Name); actionPlan.Topics.Add(new PlanTopic { TopicId = Guid.Parse(topic.Id), TopicName = topic.Name, Icon = topic.Icon, AdditionalReadings = await GetAdditionalReadings(topic.Id), Steps = GetSteps(unprocessedTopic.UnprocessedSteps, resourceDetails) }); } actionPlan.PersonalizedPlanId = Guid.NewGuid(); actionPlan.IsShared = false; return(actionPlan); }
public UnprocessedPersonalizedPlan Build(JObject personalizedPlan, CuratedExperienceAnswers userAnswers) { var stepsInScope = new List <JToken>(); var evaluatedUserAnswers = parser.Parse(userAnswers); var a2jAnswers = MapStringsToA2JAuthorValues(evaluatedUserAnswers); var root = personalizedPlan .Properties() .GetArrayValue("rootNode") .FirstOrDefault(); foreach (var child in root.GetValueAsArray <JArray>("children")) { var states = child.GetArrayValue("state"); foreach (var state in states) { foreach (var answer in a2jAnswers) { if (answer.Key == state.GetValue("leftOperand") && answer.Value == state.GetValue("operator")) { stepsInScope.Add(child); } } } } var unprocessedPlan = new UnprocessedPersonalizedPlan(); unprocessedPlan.Id = Guid.NewGuid(); var unprocessedTopic = new UnprocessedTopic(); var cultureInfo = Thread.CurrentThread.CurrentCulture; var textInfo = cultureInfo.TextInfo; unprocessedTopic.Name = textInfo.ToTitleCase(personalizedPlan.Properties().GetValue("title")); foreach (var step in stepsInScope) { foreach (var childrenRoot in step.GetValueAsArray <JArray>("children")) { var unprocessedStep = new UnprocessedStep(); foreach (var child in childrenRoot.GetValueAsArray <JObject>("rootNode").GetValueAsArray <JArray>("children")) { var state = child.GetArrayValue("state").FirstOrDefault(); unprocessedStep.Id = Guid.NewGuid(); if (!string.IsNullOrWhiteSpace(state.GetValue("title"))) { unprocessedStep.Title = state.GetValue("title"); continue; } else { if (!string.IsNullOrWhiteSpace(state.GetValue("userContent"))) { unprocessedStep.Description = state.GetValue("userContent").ExtractIdsRemoveCustomA2JTags().SanitizedHtml; unprocessedStep.ResourceIds = state.GetValue("userContent").ExtractIdsRemoveCustomA2JTags().ResourceIds; } } unprocessedTopic.UnprocessedSteps.Add(unprocessedStep); } } } unprocessedPlan.UnprocessedTopics.Add(unprocessedTopic); return(unprocessedPlan); }