示例#1
0
        private MatrixMenuAnswer MatchMatrixMenuAnswer(Question question, IEnumerable <ResponseAnswer> responseAnswers)
        {
            var reply = new MatrixMenuAnswer
            {
                Rows = new Dictionary <long, MatrixMenuAnswerRow>()
            };
            Dictionary <long, string> choicesLookup = question.AnswersLookup
                                                      .Where(answerItem => answerItem.Value.Items != null)
                                                      .SelectMany(answerItem => answerItem.Value.Items)
                                                      .ToDictionary(item => item.AnswerId, item => item.Text);

            foreach (var responseAnswer in responseAnswers)
            {
                if (responseAnswer.Row == 0)
                {
                    reply.OtherText = responseAnswer.Text;
                }
                else
                {
                    if (!reply.Rows.ContainsKey(responseAnswer.Row))
                    {
                        reply.Rows.Add(responseAnswer.Row, new MatrixMenuAnswerRow
                        {
                            Columns = new Dictionary <long, MatrixMenuAnswerColumn>()
                        });
                    }
                    if (!reply.Rows[responseAnswer.Row].Columns.ContainsKey(responseAnswer.Col))
                    {
                        reply.Rows[responseAnswer.Row].Columns.Add(responseAnswer.Col, new MatrixMenuAnswerColumn());
                    }

                    reply.Rows[responseAnswer.Row].RowName = question.AnswersLookup[responseAnswer.Row].Text;
                    reply.Rows[responseAnswer.Row].Columns[responseAnswer.Col].ColumnName = question.AnswersLookup[responseAnswer.Col].Text;
                    reply.Rows[responseAnswer.Row].Columns[responseAnswer.Col].Choice     = choicesLookup[responseAnswer.ColChoice];
                }
            }

            return(reply);
        }
        private MatrixMenuAnswer MatchMatrixMenuAnswer(Question question, IEnumerable <ResponseAnswer> responseAnswers)
        {
            if (question.Answers.Cols.Any(c => c.LegacyChoices != null))
            {
                return(null);
            }

            var reply = new MatrixMenuAnswer
            {
                Rows = new Dictionary <string, MatrixMenuAnswerRow>()
            };

            foreach (var responseAnswer in responseAnswers)
            {
                if (!String.IsNullOrEmpty(responseAnswer.Text))
                {
                    reply.OtherText = responseAnswer.Text;
                }
                else if (responseAnswer.ChoiceId.HasValue)
                {
                    if (question.Answers.ItemLookup.ContainsKey(responseAnswer.RowId.Value))
                    {
                        if (!reply.Rows.ContainsKey(question.Answers.ItemLookup[responseAnswer.RowId.Value]))
                        {
                            reply.Rows.Add(question.Answers.ItemLookup[responseAnswer.RowId.Value], new MatrixMenuAnswerRow {
                                Columns = new Dictionary <string, string>()
                            });
                        }
                        if (question.Answers.ItemLookup.ContainsKey(responseAnswer.ColId.Value) && question.Answers.ColChoicesLookup.ContainsKey(responseAnswer.ChoiceId.Value))
                        {
                            reply.Rows[question.Answers.ItemLookup[responseAnswer.RowId.Value]].Columns.Add(question.Answers.ItemLookup[responseAnswer.ColId.Value], question.Answers.ColChoicesLookup[responseAnswer.ChoiceId.Value]);
                        }
                    }
                }
            }

            return(reply);
        }
        private MatrixMenuAnswer MatchMatrixMenuAnswer(Question question, IEnumerable<ResponseAnswer> responseAnswers)
        {
            var reply = new MatrixMenuAnswer
            {
                Rows = new Dictionary<long, MatrixMenuAnswerRow>()
            };
            Dictionary<long, string> choicesLookup = question.AnswersLookup
                .Where(answerItem => answerItem.Value.Items != null)
                .SelectMany(answerItem => answerItem.Value.Items)
                .ToDictionary(item => item.AnswerId, item => item.Text);
            
            foreach (var responseAnswer in responseAnswers)
            {
                if (responseAnswer.Row == 0)
                {
                    reply.OtherText = responseAnswer.Text;
                }
                else
                {
                    if (!reply.Rows.ContainsKey(responseAnswer.Row))
                    {
                        reply.Rows.Add(responseAnswer.Row, new MatrixMenuAnswerRow
                        {
                            Columns = new Dictionary<long, MatrixMenuAnswerColumn>()
                        });
                    }
                    if (!reply.Rows[responseAnswer.Row].Columns.ContainsKey(responseAnswer.Col))
                    {
                        reply.Rows[responseAnswer.Row].Columns.Add(responseAnswer.Col, new MatrixMenuAnswerColumn());
                    }

                    reply.Rows[responseAnswer.Row].RowName = question.AnswersLookup[responseAnswer.Row].Text;
                    reply.Rows[responseAnswer.Row].Columns[responseAnswer.Col].ColumnName = question.AnswersLookup[responseAnswer.Col].Text;
                    reply.Rows[responseAnswer.Row].Columns[responseAnswer.Col].Choice = choicesLookup[responseAnswer.ColChoice];
                }   
            }

            return reply;
        }