public Choice Convert(ChoiceResource choiceResource) { var existingChoice = CreatedChoices.Where(obj => obj.Id == choiceResource.Id).FirstOrDefault(); if (existingChoice != null) { if (existingChoice is ChoiceForChoiceQuestion) { Assign(existingChoice as ChoiceForChoiceQuestion, choiceResource); } else if (existingChoice is ChoiceForTextQuestion) { Assign(existingChoice as ChoiceForTextQuestion, choiceResource); } else if (existingChoice is DefaultChoice) { Assign(existingChoice as DefaultChoice, choiceResource); } return(existingChoice); } else { if (choiceResource.DiffUpperCase != null) { var newChoice = new ChoiceForTextQuestion(); CreatedChoices.Add(newChoice); Assign(newChoice, choiceResource); return(newChoice); } else if (choiceResource.Text != null) { var newChoice = new ChoiceForChoiceQuestion(); CreatedChoices.Add(newChoice); Assign(newChoice, choiceResource); return(newChoice); } else { var newChoice = new DefaultChoice(); CreatedChoices.Add(newChoice); Assign(newChoice, choiceResource); return(newChoice); } } }
void Assign(TextQuestion textQuestion, QuestionResource questionResource) { textQuestion.Id = questionResource.Id; if (questionResource.QuestionText != null) { textQuestion.QuestionText = questionResource.QuestionText; } if ((questionResource.ChoicesThatOpensThis != null) && textQuestion.ChoicesThatOpensThis == null) { textQuestion.ChoicesThatOpensThis = new List <Choice>(); foreach (ChoiceResource choiceResource in questionResource.ChoicesThatOpensThis) { Choice newChoice = Convert(choiceResource); textQuestion.ChoicesThatOpensThis.Add(newChoice); if (newChoice.OpensQuestions == null) { newChoice.OpensQuestions = new List <Question>(); } newChoice.OpensQuestions.Add(textQuestion); } } if ((questionResource.Choices != null) && textQuestion.Choices == null) { textQuestion.Choices = new List <ChoiceForTextQuestion>(); foreach (ChoiceResource choiceResource in questionResource.Choices) { ChoiceForTextQuestion newChoice = Convert(choiceResource) as ChoiceForTextQuestion; textQuestion.Choices.Add(newChoice); newChoice.Question = textQuestion; } } if ((questionResource.DefaultChoice != null) && textQuestion.DefaultChoice == null) { DefaultChoice newChoice = Convert(questionResource.DefaultChoice) as DefaultChoice; textQuestion.DefaultChoice = newChoice; newChoice.Question = textQuestion; } }
void Assign(DefaultChoice choice, ChoiceResource choiceResource) { choice.Id = choiceResource.Id; if ((choiceResource.OpensMapPositions != null) && choice.OpensMapPositions == null) { choice.OpensMapPositions = new List <MapPosition>(); foreach (MapPositionResource mapPositionResource in choiceResource.OpensMapPositions) { MapPosition newPosition = Convert(mapPositionResource); choice.OpensMapPositions.Add(newPosition); if (newPosition.ChoicesThatOpenThis == null) { newPosition.ChoicesThatOpenThis = new List <Choice>(); } newPosition.ChoicesThatOpenThis.Add(choice); } } }