コード例 #1
0
        private void PrepareQuizResultModel(QuizResultModel model, QuizResult quizResult)
        {
            if (quizResult == null)
            {
                throw new ArgumentNullException("quizResult");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.QuizId       = quizResult.QuizId;
            model.SystemName   = quizResult.Quiz.SystemName;
            model.StudentScore = quizResult.Score;
            model.PassMark     = quizResult.Quiz.PassMark;
            model.IsSystemQuiz = quizResult.Quiz.IsSystemQuiz;
            model.IsLevelQuiz  = quizResult.Quiz.IsLevelQuiz;
            model.Questions    = new List <QuizQuestionModel>();

            foreach (var question in quizResult.Quiz.QuizQuestions.OrderBy(q => q.Id))
            {
                var quizQuestion = new QuizQuestionModel();

                quizQuestion.Question = question.Question;
                quizQuestion.Image    = question.Image;
                quizQuestion.Hint     = question.Hint;

                quizQuestion.Answers = new List <QuizAnswerModel>();
                foreach (var answer in question.QuizAnswers)
                {
                    var quizAnswer = new QuizAnswerModel();

                    quizAnswer.Id         = answer.Id;
                    quizAnswer.QuestionId = answer.QuestionId;
                    quizAnswer.Text       = answer.Text;
                    quizAnswer.IsCorrect  = answer.IsCorrect;

                    quizQuestion.Answers.Add(quizAnswer);
                }
                quizQuestion.SelectedAnswer =
                    quizResult.Answers.Where(a => a.QuestionId == question.Id).Select(q => q.AnswerId).FirstOrDefault();

                model.Questions.Add(quizQuestion);
            }
        }
コード例 #2
0
        private void PrepareQuizModel(QuizModel model, Quiz quiz)
        {
            if (quiz == null)
            {
                throw new ArgumentNullException("quiz");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id                     = quiz.Id;
            model.QuizGuid               = quiz.QuizGuid;
            model.IsSystemQuiz           = quiz.IsSystemQuiz;
            model.SystemName             = quiz.SystemName;
            model.IsLevelQuiz            = quiz.IsLevelQuiz;
            model.IsStudentQuiz          = quiz.IsStudentQuiz;
            model.PassMark               = quiz.PassMark;
            model.AchivementSystemName   = quiz.AchivementSystemName;
            model.Name                   = quiz.Name;
            model.Description            = quiz.Description;
            model.Questions              = new List <QuizQuestionModel>();
            model.NumberOfTimesQuizTaken = _quizService.GetNumberOfTimesQuizTaken(quiz.Id);
            model.NumberOfQuizComments   = _quizService.GetNumberOfQuizComments(quiz.Id);
            model.CreatedBy              = quiz.CreatedBy.Username;
            model.HasTakenQuiz           = _quizService.HasTakenQuiz(quiz.SystemName, User.Identity.Name);

            if (model.HasTakenQuiz)
            {
                model.StudentScore = _quizResultService.GetQuizResult(User.Identity.Name, quiz.Id);
            }

            // Questions
            foreach (var question in quiz.QuizQuestions)
            {
                // Answers
                var answers = new List <QuizAnswerModel>();
                foreach (var answer in question.QuizAnswers)
                {
                    var answerModel = new QuizAnswerModel
                    {
                        Id        = answer.Id,
                        Text      = answer.Text,
                        IsCorrect = answer.IsCorrect
                    };
                    answers.Add(answerModel);
                }

                var questionModel = new QuizQuestionModel
                {
                    Id       = question.Id,
                    Question = question.Question,
                    Answers  = answers,
                    Points   = question.Points,
                    Image    = question.Image,
                    Hint     = question.Hint
                };
                model.Questions.Add(questionModel);
            }
        }