public async Task RegisterPlayer(string playerName) { var player = new Player(playerName); await _playerService.AddPlayerAsync(player); await Clients.All.SendAsync("registerPlayer", player.id); }
public async Task <ActionResult <PlayerModel> > AddPlayerByUsername([FromBody] string username) { if (username == null) { return(BadRequest(ResponseMessages.PostNullObjectErrorMessage)); } try { // Check to see if player already exists var playerToCreate = await _service.GetPlayerByUsernameAsync(username); if (playerToCreate != null) { return(BadRequest($"Player {username} already exists.")); } var playerAdded = await _service.AddPlayerAsync(username); var uri = _http.HttpContext.Request.Host.Value; return(Created(uri, (PlayerModel)playerAdded)); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ResponseMessages.InternalServerErrorMessage)); } }
public async Task <ActionResult <Player> > PostPlayer(Player player) { var result = await _playerService.AddPlayerAsync(player); if (!result) { BadRequest("Player invalid"); } return(Created("api/player", player)); }
public async Task <IActionResult> AddPlayerAsync([FromRoute] int competitionId, Player playerDto) { // add event to game var eventAdded = await _playerService.AddPlayerAsync(competitionId, playerDto); if (_playerService.HasErrors) // return a bad request with errors. { return(new BadRequestObjectResult(new ApiError(_playerService.Errors))); } return(Ok(eventAdded)); }