public ActionResult Question(int CategoryId, int lobbyId) { if (SessionLogin.UserIsInSession()) { if (Session["currentQuizViewModel"] == null) { var quizVm = new CurrentQuizViewModel { CategoryId = CategoryId, lobbyId = lobbyId }; quizVm.User = userClient.GetUserByUsername(SessionLogin.UserName); quizVm.Questions = quizClient.GetAllQuestionsAndAnswersByCategoryId(CategoryId); quizVm.CurrentQuestion = quizVm.Questions.Skip(quizVm.ToSkip).Take(1).FirstOrDefault(); quizVm.ToSkip++; Session["currentQuizViewModel"] = quizVm; return(View(quizVm)); } else { CurrentQuizViewModel quizVm = (CurrentQuizViewModel)Session["currentQuizViewModel"]; if (quizVm.CategoryId != CategoryId) { SessionLogin.CloseSession(); return(RedirectToAction("Index")); //Hvis han prøver at skifte quiz undervejs !? } quizVm.CurrentQuestion = quizVm.Questions.Skip(quizVm.ToSkip).Take(1).FirstOrDefault(); quizVm.Points = (int)Session["Point"]; quizVm.ToSkip++; if (quizVm.CurrentQuestion == null) { Session["currentQuizViewModel"] = null; int totalPoint = (int)Session["Point"]; var user = userClient.GetUserByUsername(SessionLogin.UserName); user.point += totalPoint; userClient.AddPointsToUser(user); return(RedirectToAction("Finish", new { totalPoints = totalPoint, lobbyId = lobbyId })); } return(View(quizVm)); } } return(RedirectToAction("Index")); }