Пример #1
0
        public static BaseSentenceModel CreateExcerciseViewModel(GetNextSentenceResult sentenceResult, UserProfile profile)
        {
            BaseSentenceModel resultModel;
            var sentence = sentenceResult.Sentence;

            // While in Excercise Controller, sentence should either be a Sample sentence or a Question sentence
            // Review sentence would be an error
            if (sentenceResult.IsReview)
            {
                Trace.TraceError("Unexpected sentence result.  Should not receive Review sentence during excericse flow.");
            }
            if (sentenceResult.IsQuestion)
            {
                bool isGrammarQ = (sentenceResult.QuestionDimension == QuestionDimension.Grammar);

                if (!isGrammarQ)
                {
                    // If it's not grammar question it's a default contextual question
                    var model = new QuestionExcerciseViewModel(sentence.SentenceText, sentence.SentenceTranslation);
                    resultModel = model;

                    // Retriev all the Question related information from the sentence
                    PopulateQuestionFields(sentenceResult, model);
                }
                else
                {
                    // Create a Grammar Question
                    var model = new GrammarQuestionExcerciseViewModel(sentence.SentenceText, sentence.SentenceTranslation);
                    resultModel = model;

                    // Retriev all the Question related information from the sentence
                    PopulateQuestionFields(sentenceResult, model);

                    //
                    // Populate Grammar Analysis related model fields
                    PopulateGrammarAnalysisFields(sentence, model.GrammarAnalysis);

                    //
                    // Populate Grammar Entries related model fields
                    PopulateGrammarEntriesFields(sentence, model.GrammarEntries);
                }
            }
            else
            {
                // It's a regular sample sentence.  Now create right model depending on whether user is
                // Contextual or Analytical

                if (LearningTypeScorePolicies.IsAnalytical(profile))
                {
                    var model = new AnalyticalExcerciseViewModel(sentence.SentenceText, sentence.SentenceTranslation);
                    resultModel = model;

                    //
                    // Populate Grammar Analysis related model fields
                    PopulateGrammarAnalysisFields(sentence, model.GrammarAnalysis);

                    //
                    // Populate Grammar Entries related model fields
                    PopulateGrammarEntriesFields(sentence, model.GrammarEntries);
                }
                else
                {
                    var model = new ContextualExcerciseViewModel(sentence.SentenceText, sentence.SentenceTranslation);
                    resultModel = model;

                    //
                    // Populate Grammar Entries related model fields
                    PopulateGrammarEntriesFields(sentence, model.GrammarEntries);
                }
            }

            return resultModel;
        }
Пример #2
0
        private static void PopulateQuestionFields(GetNextSentenceResult sentenceResult, QuestionExcerciseViewModel model)
        {
            var sentence = sentenceResult.Sentence;
            Question q;
            if (sentence.Questions.TryGetValue(sentenceResult.QuestionDimension, out q))
            {
                model.QuestionSubText = q.QuestionSubstring;
                model.BlankIndices = q.BlankPositions;
                model.CorrectAnswerChoice = q.CorrectAnswerIndex;

                foreach (var a in q.AnswerChoices)
                {
                    ViewModelAnswerChoice vmac = new ViewModelAnswerChoice();
                    vmac.Choice = a.Answer;
                    model.AnswerChoices.Add(vmac);
                }

                foreach (var seg in q.AnswerSegments)
                {
                    AnswerSegment answerSeg = new AnswerSegment();
                    answerSeg.Text = seg;
                    model.AnswerSegments.Add(answerSeg);
                }
            }
            else
            {
                // TODO: Handle internal errors like this.  Should stop the flow?
                Trace.TraceError("Failed to get retrieve Question from sentence.");
            }
        }