示例#1
0
        // Get random question for the currently selected units.
        public Question GetRandomQuestionFromUnits(string userName, int record)
        {
            // Get user selected units.
            var units = _commonHelper.GetUserSelectedUnits(userName);

            // Get questions in random order for the currently selected units and does not match the record.
            Random random = new Random();
            var    allValidQuestionIds = _questionRepository.GetAllQuestions().Where(q => units.Contains(q.Unit) && q.Id != record).OrderBy(x => random.Next()).Select(q => q.Id);

            // Make a random selection from the randomly ordered list.
            if (allValidQuestionIds.Count() > 0)
            {
                var index = allValidQuestionIds.ElementAt(random.Next(0, allValidQuestionIds.Count() - 1));

                return(_questionRepository.GetQuestionById(index));
            }

            return(null);
        }
示例#2
0
        // Get all question id for the selected units for a user.
        private IEnumerable <int> GetAllValidQuestionId(string userName)
        {
            var units = _commonHelper.GetUserSelectedUnits(userName);

            return(_questionRepository.GetAllQuestions().Where(q => units.Contains(q.Unit)).Select(q => q.Id));
        }