private MatrixMultiAnswer MatchMatrixMultiAnswer(Question question, IEnumerable <ResponseAnswer> responseAnswers)
        {
            var reply = new MatrixMultiAnswer();

            var rows = new Dictionary <long, MatrixMultiAnswerRow>();

            foreach (var responseAnswer in responseAnswers)
            {
                if (responseAnswer.Row == 0)
                {
                    reply.OtherText = responseAnswer.Text;
                }
                else
                {
                    if (!rows.ContainsKey(responseAnswer.Row))
                    {
                        rows.Add(responseAnswer.Row, new MatrixMultiAnswerRow
                        {
                            RowName = question.AnswersLookup[responseAnswer.Row].Text,
                            Choices = new List <string>()
                        });
                    }
                    rows[responseAnswer.Row].Choices.Add(question.AnswersLookup[responseAnswer.Col].Text);
                }
            }

            reply.Rows = rows.Values.ToList();

            return(reply);
        }
        private MatrixMultiAnswer MatchMatrixMultiAnswer(Question question, IEnumerable <ResponseAnswer> responseAnswers)
        {
            var reply = new MatrixMultiAnswer();

            var rowDictionary = new Dictionary <long, MatrixMultiAnswerRow>();

            foreach (var responseAnswer in responseAnswers)
            {
                if (!responseAnswer.RowId.HasValue)
                {
                    reply.OtherText = responseAnswer.Text;
                }
                else
                {
                    if (!rowDictionary.ContainsKey(responseAnswer.RowId.Value))
                    {
                        var row = question.Answers.ItemLookup.ContainsKey(responseAnswer.RowId.Value) ? question.Answers.ItemLookup[responseAnswer.RowId.Value] : null;
                        rowDictionary.Add(responseAnswer.RowId.Value, new MatrixMultiAnswerRow
                        {
                            RowName = row,
                            Choices = new List <string>()
                        });
                    }
                    if (question.Answers.ItemLookup.ContainsKey(responseAnswer.ChoiceId.Value))
                    {
                        rowDictionary[responseAnswer.RowId.Value].Choices.Add(question.Answers.ItemLookup[responseAnswer.ChoiceId.Value]);
                    }
                }
            }

            reply.Rows = rowDictionary.Values.ToList();

            return(reply);
        }
        private MatrixMultiAnswer MatchMatrixMultiAnswer(Question question, IEnumerable<ResponseAnswer> responseAnswers)
        {
            var reply = new MatrixMultiAnswer();

            var rows = new Dictionary<long, MatrixMultiAnswerRow>();

            foreach (var responseAnswer in responseAnswers)
            {
                if (responseAnswer.Row == 0)
                {
                    reply.OtherText = responseAnswer.Text;
                }
                else
                {
                    if (!rows.ContainsKey(responseAnswer.Row))
                    {
                        rows.Add(responseAnswer.Row, new MatrixMultiAnswerRow
                        {
                            RowName = question.AnswersLookup[responseAnswer.Row].Text,
                            Choices = new List<string>()
                        });
                    }
                    rows[responseAnswer.Row].Choices.Add(question.AnswersLookup[responseAnswer.Col].Text);
                }
            }

            reply.Rows = rows.Values.ToList();

            return reply;
        }