Exemplo n.º 1
0
        public Quiz loadQuiz(QuizTypes quiztype, int numquest)
        {
            if (quizzes != null && loadedquiz == quiztype && quizzes.Count < 0)
            {
                currentq = 0;
                return(next());
            }

            else
            {
                FileStream fs        = null;
                string     questions = null;
                switch (quiztype)
                {
                case QuizTypes.EASY:
                    loadedquiz = QuizTypes.EASY;
                    fs         = new FileStream("questions.json", FileMode.Open, FileAccess.Read);
                    break;

                case QuizTypes.MEDIUM:
                    loadedquiz = QuizTypes.MEDIUM;
                    break;

                case QuizTypes.HARD:
                    loadedquiz = QuizTypes.HARD;
                    break;

                default:
                    loadedquiz = QuizTypes.EASY;
                    fs         = new FileStream("questions.json", FileMode.Open, FileAccess.Read);
                    break;
                }

                using (StreamReader sr = new StreamReader(fs))
                {
                    questions = sr.ReadToEnd();
                }

                quizzes = JsonConvert.DeserializeObject <List <Quiz> >(questions);
                Shuffle();
                currentq     = 1;
                currentIndex = 0;
                if (quizzes.Count < numquest)
                {
                    numofquestions = quizzes.Count;
                }
                else
                {
                    numofquestions = numquest;
                }
            }



            //shuffle quiz
            quizzes[currentIndex].choices = shuffleAnswers(quizzes[currentIndex].choices);
            return(quizzes[currentIndex]);
        }
Exemplo n.º 2
0
        public Result GetQuizByType(QuizTypes type)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            //ASSeSSMENT QUIZZES GET BY DOMAIN NO TYPE
            if (QuizTypes.ASSESSMENT == type)
            {
                result.Success = false;
                return(result);
            }

            query.Query  = @"SELECT * FROM Quizzes
                            where Type = @Type";
            query.Entity = new { Type = type.ToString() };

            result = con.ExecuteQuery <QuizEntity>(query);

            if (!result.Success)
            {
                result.Message = "An error occurred";
                return(result);
            }

            var r = (IEnumerable <QuizEntity>)result.Entity;

            var quiz = r.FirstOrDefault();

            if (quiz == null)
            {
                //new quiz needs to be inserted
                quiz = new QuizEntity
                {
                    Name = type.ToString(),
                    Type = type.ToString()
                };
                result = Insert(quiz, con);
            }
            else
            {
                var resultQ = GetQuestionsByQuiz(quiz.QuizId, con);
                if (!resultQ.Success)
                {
                    return(resultQ);
                }
                quiz.Questions = (List <QuestionEntity>)resultQ.Entity;
            }
            result.Entity = quiz;
            return(result);
        }
 public void SetSelectedQuizType(QuizTypes type)
 {
     Debug.Log("SetSelectedQuizType " + type);
     _selectedQuizType = type;
 }