public async Task <IActionResult> JoinGame([FromBody] PlayerGameDto playerGame) { if (!ModelState.IsValid) { return(BadRequest()); } var user = await playerRepository.GetPlayerById(playerGame.PlayerId); var game = lobbyHelper.GetGameDto(playerGame.GameId); if (user == null || game == null) { return(BadRequest()); } var response = lobbyHelper.AddPlayerToGame(game.Id, user); if (response.Item1) { await logUserActivity.GameLogin(user, game); return(Ok(game)); } return(BadRequest()); }
public static PlayerGameDto ToPlayerGameDto(this Player player, Game game) { var tempDto = new PlayerGameDto(); tempDto.PlayerId = player.Id; tempDto.GameId = game.GameKey; return(tempDto); }
public async Task <IActionResult> LeaveGame([FromBody] PlayerGameDto playerGame) { if (!ModelState.IsValid) { return(BadRequest()); } var user = await playerRepository.GetPlayerById(playerGame.PlayerId); var game = lobbyHelper.GetGameDto(playerGame.GameId); var response = lobbyHelper.RemovePlayerFromGame(game.Id, user); if (response.Item1) { var result = await logUserActivity.GameLogout(user, game); if (result) { return(Ok()); } } return(BadRequest()); }