public async Task LeaveGame() { if (!_game.LeaveGame(Context.ConnectionId)) { var exception = new SudokuHubException("user can not leave game"); exception.Data["connection id"] = Context.ConnectionId; throw exception; } await ListGamers(); }
public async Task AddNumber(int row, int column, int value) { if (!_game.AddNumber(row, column, value, _game.GetGamer(Context.ConnectionId))) { return; } await Clients.All.SendCoreAsync("AddNumber", new object[] { new SudokuNumber { Row = row, Column = column, Value = value } }); if (_game.GameStatus() == SudokuGameStatus.Solved) { var winnerGuid = _game.GetWinner(); if (winnerGuid == null) { var exception = new SudokuHubException("winner not found in game"); exception.Data["connection id"] = Context.ConnectionId; throw exception; } var winner = _userRepository.GetByGuid(winnerGuid.Value); if (winner == null) { var exception = new SudokuHubException("winner not found in repository"); exception.Data["connection id"] = Context.ConnectionId; throw exception; } _userRepository.UpdateWins(winner.Guid, winner.Wins + 1); await UpdateTop(); } }