public QuizPlayViewmodel PlayHelper(QuizPlayViewmodel model, string answer)
        {
            //If not first question
            if (model.CurrentQuestionNr != 0 && model.CurrentQuestionId != 0)
            {
                var currentQuestion = rep.GetQuizQuestion(model.CurrentQuestionId);

                //If right answer
                if (answer == currentQuestion.CorrectAnswer)
                {
                    model.Score += 1;
                    model.PreviousQuestionCorrect = true;
                }
                else
                {
                    model.PreviousQuestionCorrect = false;
                }

                model.PreviousQuestion = model.CurrentQuestion;
                model.PreviousGivenAnswer = answer;
                model.PreviousCorrectAnswer = currentQuestion.CorrectAnswer;

                if (model.AnsweredQuestions == null)
                {
                    model.AnsweredQuestions = new List<int>();
                }

                model.AnsweredQuestions.Add(model.CurrentQuestionId);
            }

            model.CurrentQuestionNr += 1;

            var nextQuestion = rep.GetRandomQuestion(model.AnsweredQuestions,model.CategoryId);

            model.CurrentQuestion = nextQuestion.Question;
            model.CurrentQuestionId = nextQuestion.Id;
            model.Answers = nextQuestion.Answers.Select(q => q.Answer).ToList();

            return model;
        }
        public ActionResult Play(QuizPlayViewmodel model, string answer)
        {
            int nrOfQuestions;

            //15 random questions
            if (model.CategoryId == null)
            {
                nrOfQuestions = 15;
            }
            //5 question of specified category
            else
            {
                nrOfQuestions = 5;
            }

            if (model.CurrentQuestionNr >= nrOfQuestions)
            {
                return RedirectToAction("Result", new QuizResultViewmodel() { CategoryId = model.CategoryId, CategoryName = model.CategoryName, Score = model.Score });
            }
            else
            {
                return View(PlayHelper(model,answer));
            }
        }
        public ActionResult Play(int? categoryId)
        {
            var model = new QuizPlayViewmodel(rep.GetQuizCategory(categoryId));

            return View(PlayHelper(model,null));
        }