예제 #1
0
        public async Task <PlayerResponse> CreatePlayer(string name)
        {
            var newPlayer = new PlayerUpsert {
                Name = name
            };
            var response = await _controller.AddPlayer(newPlayer);

            return(response.Get <PlayerResponse>());
        }
예제 #2
0
            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);
            }
예제 #3
0
        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));
            }
        }
예제 #4
0
            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);
            }
예제 #5
0
        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
            });
        }
예제 #6
0
        public async Task <ActionResult <PlayerResponse> > AddPlayer([FromBody] PlayerUpsert playerCreate)
        {
            var newPlayer = await _repo.Add(playerCreate);

            return(CreatedAtRoute(nameof(GetSinglePlayer), new { id = newPlayer.Id }, newPlayer));
        }
예제 #7
0
        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));
        }