Exemple #1
0
        // GET: Quiz
        //PlayArena: In that momemnt you click a level in a specific room.
        //UserID = ID number in AspnetUser
        //x (models.Question). It is main question (question.id) and its possible answers. Loops 10 times. It orders the id of the questions!
        //The player_status is based on the specifik room on a specific level. Afterwards finding that player and adding it in the table!
        //57: For each questions (10) populating them and its answers in the viewmodel.
        //Getting the 10 questions by giving a levelID. Afterwards populating the data in the viewModels! If questions is empty, then generate 10 random questions.
        //Linie 43 if 10 keep going or empty generate!
        //Creating a player_status. Populating level,room as objects and get a specific room_level_id (info).
        //If the list of questions are empty then it should generate random-questions (loading the page for first time), if not then we keep the questions until the user is finished (loading for second time).
        // Linie 48: It retrieves the already generated questions which are not finished yet and then ordering the questions by their ID's. We save them as well for resuming the game.
        //Populating the viewmodel properties withe question and answers --> because of validating the correct ID's
        //Players are connected on (same level id and roomID) = same questions.
        public ActionResult Index(int levelID, int roomID)
        {
            int             userID = int.Parse(User.Identity.GetUserId());
            List <Question> question;


            question = questionLogic.playerQuestion(roomID, levelID);
            if (question.Count == 0)
            {
                question = questionLogic.Get10Questions(levelID);
                questionLogic.savePlayerUnfinishedQuiz(question, levelID, roomID);
            }
            question = question.OrderBy(x => x.ID).ToList();

            QuizViewModel viewModel = new QuizViewModel();

            viewModel.LevelID = levelID;
            viewModel.RoomID  = roomID;

            viewModel.questions = new List <QuestionViewModels>();

            foreach (var item in question)
            {
                QuestionViewModels questionViewModel = new QuestionViewModels();
                questionViewModel.QuestionID    = item.ID;
                questionViewModel.QuestionTitle = item.Title;
                questionViewModel.Answers       = new List <AnswerViewModel>();

                foreach (var answers in item.Answers)
                {
                    AnswerViewModel answerViewModel = new AnswerViewModel();
                    answerViewModel.AnswerText = answers.AnswerText;
                    answerViewModel.ID         = answers.ID;


                    questionViewModel.Answers.Add(answerViewModel);
                }

                viewModel.questions.Add(questionViewModel);
            }
            return(View(viewModel));
        }