Beispiel #1
0
        public IActionResult SelectQuizDifficulty()
        {
            _quizFlow.ResetSession(); //user may have less the screen so reset quiz session

            var viewModel = new QuizDifficultyViewModel();

            return(View(viewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> QuizView(QuizDifficultyViewModel userEnteredQuestion, string pokemonName) //feeding into eds
        {
            var quizModel = await _quizFlow.SetupQuiz(userEnteredQuestion, pokemonName);

            if (quizModel.PokemonAnswers.Count == 0)
            {
                var quizResults = await _quizFlow.SetQuizResults();

                await _pokemonUserSQLService.CreatePokemonUserData(quizResults);

                return(View("QuizResults", quizResults));
            }
            return(View(quizModel));
        }
Beispiel #3
0
        public async Task <IActionResult> Index()
        {
            var model = new QuizDifficultyViewModel();

            model.SelectedNumberOfQuestions = 2;
            string name   = null;
            var    models = await _quizFlow.SetupQuiz(model, name);

            var startModel = new PlayerRankModel();

            startModel = await _playerService.AssemblePlayerRank();

            return(View(startModel));
        }
        public async Task <QuizViewModel> SetupQuiz(QuizDifficultyViewModel userEnteredQuestion, string pokemonName)
        {
            var quizModel    = new QuizViewModel();
            var testSession  = _session.GetString("answerList");
            var testSession2 = _session.GetString("userAnswer");

            if (testSession != null)
            {
                quizModel.ListOfAnswers = JsonConvert.DeserializeObject <List <string> >(_session.GetString("answerList"));
            }

            if (pokemonName != null)
            {
                if (testSession2 != null)
                {
                    quizModel.UserAnswers = JsonConvert.DeserializeObject <List <string> >(_session.GetString("userAnswer"));
                }

                quizModel.UserAnswers.Add(pokemonName);
                var sessionUserAnswers = JsonConvert.SerializeObject(quizModel.UserAnswers);
                _session.SetString("userAnswer", sessionUserAnswers);
            }

            var totalCorrectAnswers = _session.GetInt32("amountCorrect").GetValueOrDefault();

            if (pokemonName == _session.GetString("pokemonAnswer") & pokemonName != null)
            {
                totalCorrectAnswers++;

                _session.SetInt32("amountCorrect", totalCorrectAnswers);
            }
            quizModel.QuestionsCorrect = _session.GetInt32("amountCorrect").GetValueOrDefault();

            if (userEnteredQuestion.SelectedNumberOfQuestions != 0)
            {
                _session.SetInt32("questionsAttempted", userEnteredQuestion.SelectedNumberOfQuestions);
            }

            userEnteredQuestion.SelectedNumberOfQuestions = userEnteredQuestion.SelectedNumberOfQuestions + 1;

            if (quizModel.PokemonAnswers.Count == 0)
            {
                quizModel.PokemonAnswers = _randomizer.RandomizeListOfAnsweres(userEnteredQuestion.SelectedNumberOfQuestions);
            }
            var testString = _session.GetString("pokemonStack");

            if (testString != null)
            {
                quizModel.PokemonAnswers = JsonConvert.DeserializeObject <Stack <int> >(_session.GetString("pokemonStack"));
            }
            quizModel.CorrectPokemon = await _pokemonService.MapPokemonInfo(quizModel.PokemonAnswers.Peek());

            quizModel.CorrectPokemon.IsCorrect = true;
            var listOfWrongAnswers = _randomizer.RandomizeAditionalPokemon(quizModel.PokemonAnswers.Peek(), 4);

            quizModel.WrongAnswer1 = await _pokemonService.MapPokemonInfo(listOfWrongAnswers[0]);

            quizModel.WrongAnswer2 = await _pokemonService.MapPokemonInfo(listOfWrongAnswers[1]);

            quizModel.WrongAnswer3 = await _pokemonService.MapPokemonInfo(listOfWrongAnswers[2]);

            _session.SetString("pokemonAnswer", quizModel.CorrectPokemon.PokemonName);

            if (quizModel.PokemonAnswers.Count != 1)
            {
                quizModel.ListOfAnswers.Add(quizModel.CorrectPokemon.PokemonName);
            }
            quizModel.PokemonAnswers.Pop();

            var storeStackIntoString      = JsonConvert.SerializeObject(quizModel.PokemonAnswers);
            var storeAnswerListIntoString = JsonConvert.SerializeObject(quizModel.ListOfAnswers);

            _session.SetString("pokemonStack", storeStackIntoString);
            _session.SetString("answerList", storeAnswerListIntoString);



            quizModel.QuizAnswers.Add(quizModel.CorrectPokemon);
            quizModel.QuizAnswers.Add(quizModel.WrongAnswer1);
            quizModel.QuizAnswers.Add(quizModel.WrongAnswer2);
            quizModel.QuizAnswers.Add(quizModel.WrongAnswer3);
            quizModel.QuizAnswers = _randomizer.RandomizePossibleAnswerOrder(quizModel.QuizAnswers);

            return(quizModel);
        }
Beispiel #5
0
 public IActionResult QuizView(QuizDifficultyViewModel userEnteredQuestion) //feeding into eds
 {
     return(View());
 }
Beispiel #6
0
        public IActionResult SelectQuizDifficulty()
        {
            var viewModel = new QuizDifficultyViewModel();

            return(View(viewModel));
        }