public async Task <ActionResult> Play(string id) { if (id == null || id.Length != TechnicalConstants.GameIdLength) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (UnitOfWork unitOfWork = new UnitOfWork()) { GameState gameState = await unitOfWork.GameRepository.GetGameStateAsync(id); if (gameState == GameState.Undefined) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } switch (gameState) { case GameState.Playing: GamePlayViewModel gamePlayVM = await unitOfWork.GameQuestionsRepository.GetGamePlayVMAsync(id); return(View("Play", gamePlayVM)); case GameState.LastQuestionAnswered: GuessViewModel firstGuessVM = await unitOfWork.GameRepository.GetGuessVMAsync(id); return(View("FirstGuessFeedback", firstGuessVM)); case GameState.FirstGuessMarkedCorrect: case GameState.SelectedFromTopGuessesList: case GameState.EnteredWhoItWas: GuessViewModel guessVM = await unitOfWork.GameRepository.GetGuessVMAsync(id); return(View("CorrectGuess", guessVM)); case GameState.FirstGuessMarkedIncorrect: TopGuessesViewModel topGuessesVM = await unitOfWork.GameEntityRepository.GetTopGuessesVMAsync(id); return(View("TopGuesses", topGuessesVM)); case GameState.MustEnterWhoItWas: SubmitNewEntityViewModel newEntitySubmissionVM = new SubmitNewEntityViewModel { AccessID = id, SubmittedEntity = new Entity() }; return(View("SubmitNewEntity", newEntitySubmissionVM)); default: return(null); } } }
public async Task <TopGuessesViewModel> GetTopGuessesVMAsync(string gameAccessId) { Game game = await this.unitOfWork.GameRepository.GetGameFromAccessIdAsync(gameAccessId); this.unitOfWork.GameRepository.UpdateGameActivityNoSave(game); await this.dbContext.SaveChangesAsync(); TopGuessesViewModel topGuessesVM = new TopGuessesViewModel(); topGuessesVM.AccessID = gameAccessId; topGuessesVM.TopGuesses = await this.dbContext .Set <GameEntity>() .Where(ge => ge.Game.IDGame == game.IDGame) .OrderByDescending(ge => ge.Fitness) .Skip(1) .Take(Constants.GamePlayConstants.MaxAlternativeEntities) .Select(ge => ge.Entity) .ToListAsync(); return(topGuessesVM); }