Пример #1
0
        // Get multiple choice question for the currently selected units based on question selection algorithm.
        public Question GetMultipleChoiceQuestionBasedOnRating(string userName)
        {
            // Get the currently selected units.
            var units = _commonHelper.GetSelectedUnitsList(userName).Select(u => u.SelectedUnitId);

            // Find new question.
            var question = _questionRepository.GetAllQuestions().Where(q => !_questionRatingRepository.GetAllRatings().Where(r => r.UserName == userName).Select(r => r.QuestionId).Contains(q.Id) && units.Contains(q.UnitId)).FirstOrDefault();

            // If no new questions found look for question on different criteria.
            if (question is null)
            {
                // Find lowest rated question id.
                var nextQuestionId = _questionRatingRepository.GetAllRatings().Where(r => r.UserName == userName && units.Contains(r.Question.UnitId) && r.Time < DateTime.Now.AddHours(-1) && r.Rating < 6).OrderBy(r => r.Time).FirstOrDefault();

                // If no low rated questions due to be shown look for oldest question id.
                if (nextQuestionId is null)
                {
                    // Get oldest rated question id.
                    nextQuestionId = _questionRatingRepository.GetAllRatings().Where(r => r.UserName == userName && units.Contains(r.Question.UnitId)).OrderBy(r => r.Time).FirstOrDefault();
                }

                if (nextQuestionId != null)
                {
                    // Get the question from the selected id.
                    question = _questionRepository.GetQuestionById(nextQuestionId.QuestionId);
                }
            }

            return(question);
        }
Пример #2
0
        // Get list of all questions for the selected units.
        public List <Question> GetAllQuestions(string userName)
        {
            // Get user selected units.
            var units = _commonHelper.GetSelectedUnitsList(userName).Select(u => u.SelectedUnitId);

            // Get all questions where the unit has been selected.
            var questions = _questionRepository.GetAllQuestions()
                            .Join(_unitRepository.GetAllUnits().Where(u => units.Contains(u.Id)), q => q.UnitId, u => u.Id,
                                  (q, u) => new Question
            {
                Answer1       = q.Answer1,
                Answer2       = q.Answer2,
                Answer3       = q.Answer3,
                Answer4       = q.Answer4,
                Content       = q.Content,
                CorrectAnswer = q.CorrectAnswer,
                Id            = q.Id,
                Reference     = q.Reference,
                UnitId        = q.UnitId,
                Unit          = u
            }).OrderBy(q => q.Id).ToList();

            return(questions);
        }