public async Task <ActionResult> Post([FromBody] PlayerPostRequestModel newPlayer) { // Save player var player = new Player { UserId = newPlayer.UserId, Gamertag = newPlayer.Gamertag, Country = newPlayer.Country, CustomTag = newPlayer.CustomTag }; await _store.SavePlayerAsync(player); // Return result return(CreatedAtRoute(nameof(GetPlayer), new { gamertag = player.Gamertag }, null)); }
public async Task <ActionResult> Post([FromBody] PlayerPostRequestModel newPlayer) { if (string.IsNullOrWhiteSpace(newPlayer.Gamertag)) { return(BadRequest()); //TODO: return error info in body } // Save player var player = new Player { UserId = newPlayer.UserId ?? Guid.NewGuid().ToString(), Gamertag = newPlayer.Gamertag, Country = newPlayer.Country, CustomTag = newPlayer.CustomTag }; await _store.SavePlayerAsync(player); // Return result return(CreatedAtRoute(nameof(GetPlayer), new { gamertag = player.Gamertag }, null)); }
public async Task <ActionResult> Post([FromBody] PlayerPostRequestModel newPlayer) { if (!ModelState.IsValid) { // TODO log and return validation message return(BadRequest()); } // Save player var player = new Player { UserId = newPlayer.UserId, Gamertag = newPlayer.Gamertag, Country = newPlayer.Country, CustomTag = newPlayer.CustomTag }; await _store.SavePlayerAsync(player); // Return result return(CreatedAtRoute(nameof(GetPlayer), new { gamertag = player.Gamertag }, null)); }