Ejemplo n.º 1
0
        public void ViewModelFactory_CreatesCorrectPlayerView()
        {
            PlayerViewModel result = ViewModelFactory.CreatePlayerViewModel(PlayerDataModel);

            Assert.AreEqual(PlayerDataModel.Id, result.Id);
            Assert.AreEqual(PlayerDataModel.Name, result.Name);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetPlayer([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PlayerDataModel player = await _context.Players.FindAsync(id);

            if (player == null)
            {
                return(NotFound());
            }

            return(Ok(ViewModelFactory.CreatePlayerViewModel(player)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostPlayer([FromBody] CreatePlayerRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PlayerDataModel player = new PlayerDataModel
            {
                Name         = request.Name,
                CreationDate = DateTime.Now
            };

            _context.Players.Add(player);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPlayer", new { id = player.Id }, ViewModelFactory.CreatePlayerViewModel(player)));
        }
Ejemplo n.º 4
0
 public IEnumerable <PlayerViewModel> GetPlayers()
 {
     return(_context.Players.Select(p => ViewModelFactory.CreatePlayerViewModel(p)));
 }