public async Task <PlayerResponse> CreatePlayer(string name) { var newPlayer = new PlayerUpsert { Name = name }; var response = await _controller.AddPlayer(newPlayer); return(response.Get <PlayerResponse>()); }
public async void ShouldBeAbleToUpdatePlayer() { var updatedPlayer = new PlayerUpsert() { Name = "Updated Dalek" }; var response = await _controller.UpdatePlayer(existingPlayer.Id, updatedPlayer); response.Get <PlayerResponse>().Name.Should().Be(updatedPlayer.Name); }
public async Task <ActionResult <PlayerResponse> > UpdatePlayer(int id, [FromBody] PlayerUpsert playerUpdate) { var(status, player) = await _repo.Update(id, playerUpdate); switch (status) { case PlayersRepositoryStatus.Updated: return(Ok(player)); default: return(NotFound(id)); } }
public async Task ShouldBeAbleToAddValidPlayer() { var newPlayer = new PlayerUpsert { Name = "Davros Dalek" }; var response = await _controller.AddPlayer(newPlayer); Console.WriteLine("En Gang"); response.Result.Should().BeOfType <CreatedAtRouteResult>(); response.Get <PlayerResponse>().Name.Should().Be(newPlayer.Name); }
public async Task <PlayerResponse> Add(PlayerUpsert playerCreate) { var player = new Player { Name = playerCreate.Name, Created = DateTime.Now }; _dbContext.Players.Add(player); await _dbContext.SaveChangesAsync(); await _dbContext.Entry(player).ReloadAsync(); return(new PlayerResponse { Name = player.Name, Id = player.PlayerId }); }
public async Task <ActionResult <PlayerResponse> > AddPlayer([FromBody] PlayerUpsert playerCreate) { var newPlayer = await _repo.Add(playerCreate); return(CreatedAtRoute(nameof(GetSinglePlayer), new { id = newPlayer.Id }, newPlayer)); }
public async Task <(PlayersRepositoryStatus Status, PlayerResponse Player)> Update(int id, PlayerUpsert player) { var playerToUpdate = await _dbContext.Players.FindAsync(id); if (playerToUpdate == null) { return(PlayersRepositoryStatus.NotFound, null); } playerToUpdate.Name = player.Name; await _dbContext.SaveChangesAsync(); return(PlayersRepositoryStatus.Updated, MapPlayerToPlayerResponse(playerToUpdate)); }