private MultipleChoiceAnswer MatchMultipleChoiceAnswer(Question question, IEnumerable <ResponseAnswer> responseAnswers) { var reply = new MultipleChoiceAnswer { Choices = new List <string>() }; foreach (var responseAnswer in responseAnswers) { //The API occasionally returns an invalid empty answer like "answers":[{"row":"0"},{"row":"123456789"}] //Confirmed by SM as their problem, but need to ignore in the library to avoid a KeyNotFoundException which blows up data processing if (responseAnswer.Row != 0) { if (question.AnswersLookup[responseAnswer.Row].Type == AnswerType.Row) { reply.Choices.Add(question.AnswersLookup[responseAnswer.Row].Text); } if (question.AnswersLookup[responseAnswer.Row].Type == AnswerType.Other) { reply.Choices.Add(question.AnswersLookup[responseAnswer.Row].Text); reply.OtherText = responseAnswer.Text; } } } return(reply); }
private MultipleChoiceAnswer MatchMultipleChoiceAnswer(Question question, IEnumerable <ResponseAnswer> responseAnswers) { var reply = new MultipleChoiceAnswer { Choices = new List <string>() }; foreach (var responseAnswer in responseAnswers) { if (responseAnswer.OtherId.HasValue) { reply.OtherText = responseAnswer.Text; } if (responseAnswer.ChoiceId.HasValue && responseAnswer.ChoiceId != 0 && question.Answers.ItemLookup.ContainsKey(responseAnswer.ChoiceId.Value)) { reply.Choices.Add(question.Answers.ItemLookup[responseAnswer.ChoiceId.Value]); } } return(reply); }
private MultipleChoiceAnswer MatchMultipleChoiceAnswer(Question question, IEnumerable<ResponseAnswer> responseAnswers) { var reply = new MultipleChoiceAnswer { Choices = new List<string>() }; foreach (var responseAnswer in responseAnswers) { //The API occasionally returns an invalid empty answer like "answers":[{"row":"0"},{"row":"123456789"}] //Confirmed by SM as their problem, but need to ignore in the library to avoid a KeyNotFoundException which blows up data processing if (responseAnswer.Row != 0) { if (question.AnswersLookup[responseAnswer.Row].Type == AnswerType.Row) { reply.Choices.Add(question.AnswersLookup[responseAnswer.Row].Text); } if (question.AnswersLookup[responseAnswer.Row].Type == AnswerType.Other) { reply.Choices.Add(question.AnswersLookup[responseAnswer.Row].Text); reply.OtherText = responseAnswer.Text; } } } return reply; }