public string submitQuiz(QuizViewModel model) { int userid = int.Parse(User.Identity.GetUserId()); var room_level = room_LevelsLogic.getRoom_level(model.RoomID, model.LevelID); int correctedAnswers = 0; foreach (var question in model.questions) { var isCorrect = questionLogic.isAnsweredCorrect(question.SelectedAnswerID); if (isCorrect) { correctedAnswers++; } } Player player = UserLogic.findPLayer(userid); Player_Status playerStatus = player_StatusLogic.findPlayerStatus(player, room_level); playerStatus.SavedScore = correctedAnswers; if (playerStatus.SavedScore < room_level.Level.Score) { playerStatus.Warnings++; } player_StatusLogic.updatePlayerStatus(playerStatus); //Getting all the players in the room. The first room_level is open and looking at their results in a given level. If the player is done yet or the score is less than score, they are not carrying on. //If they have cope with the score, they go to the next level. //For all players we are looking at their room_levels (player_status) (player_room_levels). Still setting the same room_level. List <Player> players = RoomLogic.FindAllPlayerOneRoom(model.RoomID); bool isCompleted = true; foreach (Player roomPlayer in players) { Player_Status player_status = player_StatusLogic.findPlayerStatus(roomPlayer, room_level); if (player_status == null || player_status.SavedScore < room_level.Level.Score) { isCompleted = false; } } //If completed we find the next room_level id and open it up for each players. if (isCompleted) { foreach (Player roomPlayer in players) { Room_levels nextRoomLevel = room_LevelsLogic.getRoom_level(model.RoomID, room_level.Level.Next_level); Player_Status nextPlayerStatus = player_StatusLogic.findPlayerStatus(roomPlayer, nextRoomLevel); nextPlayerStatus.IsUnlocked = true; player_StatusLogic.updatePlayerStatus(nextPlayerStatus); } } //Udpdating the current one u have played room_LevelsLogic.updateRoomLevel(room_level); questionLogic.deletePlayerQuestions(model.LevelID, model.RoomID); if (playerStatus.Warnings == 1) { //gult kort return("Du har svaret rigtigt på " + correctedAnswers.ToString() + "/10. Det er ikke nok. Du har fået et gult kort!"); } else if (playerStatus.Warnings == 2) { //rødt kort return("Du har svaret rigtigt på " + correctedAnswers.ToString() + "/10. Det er ikke nok. Du har fået rødt kort og er blevet sparket af holdet!!"); } return("Du har svaret rigtigt på " + correctedAnswers.ToString() + "/10"); }