Example #1
0
        public Question GetQuestion()
        {
            string        subject   = String.Empty;
            List <string> options   = new List <string>();
            int           randomInt = randy.Next(1, QuestionsBank.Count);

            // Getting a random question making sure it exists and that its not the previous question
            while (!QuestionsBank.ContainsKey(randomInt) && randomInt != prevRand)
            {
                randomInt = randy.Next(1, QuestionsBank.Keys.Max());
            }
            prevRand = randomInt;
            string phrase = QuestionsBank[randomInt];
            // Getting the query for the question and proccessing the data
            JArray jerry1 = dataBase.GetDataFromDB(qManager.GetQuestionQuery(randomInt));

            // Getting the question subject if it has one and trimming it
            if (HasPlaceholder(phrase))
            {
                foreach (JToken entry in jerry1)
                {
                    subject = entry["template"].ToString().TrimEnd('\r', '\n');
                }
            }
            // Getting the correct answer
            string correctAnswer = String.Empty;

            foreach (JToken entry in jerry1)
            {
                correctAnswer = entry["answer"].ToString().Trim();
            }
            options.Add(correctAnswer);
            // Getting the false answers for the question
            JArray jerry2 = dataBase.GetDataFromDB(qManager.GetFalseQuestionQuery(randomInt));

            foreach (JToken entry in jerry2)
            {
                options.Add(entry["false_answer"].ToString().Trim());
            }
            return(new Question(phrase, options, correctAnswer, subject));
        }