public async Task RollDice() { var playerRollingDice = await _gameContext.FindPlayerByIdIncludeGameState(Context.ConnectionId); if (playerRollingDice == null) { await Clients.Caller.SendAsync("ErrorFromServer", "Your player Id could Not be found"); } else { var gameState = playerRollingDice.GameState; var roomCode = gameState.RoomCode; if (playerRollingDice.Dice == null) { playerRollingDice.Dice = GameLogic.RollDice(); _gameContext.Players.Update(playerRollingDice); } else { await Clients.Caller.SendAsync("ErrorFromServer", "You already have dice. Please reset the game if you wish to get new dice"); } if (await _gameLogic.AllDiceRolled(roomCode) && gameState.LoserId == null && gameState.ActivePlayerId == null) { await _gameLogic.SetNextActivePlayer(roomCode); } else if (await _gameLogic.AllDiceRolled(roomCode) && gameState.ActivePlayerId == null) { gameState.ActivePlayerId = gameState.LoserId; _gameContext.GameStates.Update(gameState); } await _gameContext.SaveChangesAsync(); var playerDtos = new PlayersDto(await _gameContext.FindPlayersByGameStateOrderBySeatNumAsc(gameState)); var playerListAndGameState = new Dictionary <string, object> { { "playerList", playerDtos }, { "gameState", new GameStateDto(await _gameContext.GameStates.FindAsync(roomCode), _gameContext.Players) } }; await Clients.Caller.SendAsync("GetDiceBack", new PlayerDtoSansGameState(playerRollingDice)); await Console.Out.WriteLineAsync("Rolling Dice"); await Clients.Group(roomCode).SendAsync("PlayerList", playerListAndGameState); } }