public async Task <Tuple <string, JourneyViewModel> > JustToBeSafeNextBuilder(JustToBeSafeViewModel model) { model.State = JsonConvert.DeserializeObject <Dictionary <string, string> >(model.StateJson); var questionsWithAnswers = JsonConvert.DeserializeObject <List <QuestionWithAnswers> >(model.QuestionsJson); var selectedQuestion = questionsWithAnswers.FirstOrDefault(q => q.Question.Id == model.SelectedQuestionId); var selectedAnswer = model.SelectedNoneApply() ? new Answer() : selectedQuestion.Answers.FirstOrDefault(a => a.Title.ToLower().StartsWith("yes")) ?? new Answer(); var journey = JsonConvert.DeserializeObject <Journey>(model.JourneyJson).Add( new Journey { Steps = questionsWithAnswers. Select(q => new JourneyStep { QuestionId = q.Question.Id, QuestionNo = q.Question.QuestionNo, QuestionTitle = q.Question.Title, Answer = q.Question.Id == model.SelectedQuestionId ? selectedAnswer : q.Answers.First(a => a.Title.ToLower().StartsWith("no")), IsJustToBeSafe = true }).ToList() }); var questionsJson = await _restfulHelper.GetAsync(string.Format(_configuration.BusinessApiJustToBeSafePartTwoUrl, model.PathwayId, model.SelectedQuestionId ?? "", String.Join(",", questionsWithAnswers.Select(question => question.Question.Id)), selectedQuestion != null && selectedQuestion.Answers.Count > 3)); var questions = JsonConvert.DeserializeObject <List <QuestionWithAnswers> >(questionsJson); journey.Steps = journey.Steps.Where(step => !questions.Exists(question => question.Question.Id == step.QuestionId)).ToList(); return(await BuildNextAction(questions, journey, model, selectedAnswer, selectedQuestion, questionsJson)); }
public async Task <Tuple <string, JourneyViewModel> > JustToBeSafeNextBuilder(JustToBeSafeViewModel model) { model.State = JsonConvert.DeserializeObject <Dictionary <string, string> >(model.StateJson); var questionsWithAnswers = JsonConvert.DeserializeObject <List <QuestionWithAnswers> >(model.QuestionsJson); var selectedQuestion = questionsWithAnswers.FirstOrDefault(q => q.Question.Id == model.SelectedQuestionId); var selectedAnswer = model.SelectedNoneApply() ? new Answer() : selectedQuestion.Answers.FirstOrDefault(a => a.Title.ToLower().StartsWith("yes")) ?? new Answer(); var journey = JsonConvert.DeserializeObject <Journey>(model.JourneyJson).Add( new Journey { Steps = questionsWithAnswers. Select(q => new JourneyStep { QuestionType = q.Question.QuestionType, QuestionId = q.Question.Id, QuestionNo = q.Question.QuestionNo, QuestionTitle = q.Question.Title, Answer = q.Question.Id == model.SelectedQuestionId ? selectedAnswer : q.Answers.First(a => a.Title.ToLower().StartsWith("no")), IsJustToBeSafe = true }).ToList() }); var url = _configuration.GetBusinessApiJustToBeSafePartTwoUrl(model.PathwayId, model.SelectedQuestionId ?? "", String.Join(",", questionsWithAnswers.Select(question => question.Question.Id)), selectedQuestion != null && selectedQuestion.Answers.Count > 3); var response = await _restClient.ExecuteAsync <IEnumerable <QuestionWithAnswers> >(new JsonRestRequest(url, Method.GET)); CheckResponse(response); var questions = response.Data.ToList(); journey.Steps = journey.Steps.Where(step => !questions.Exists(question => question.Question.Id == step.QuestionId)).ToList(); return(await BuildNextAction(questions, journey, model, selectedAnswer, selectedQuestion, JsonConvert.SerializeObject(response.Data))); }