public void ViewModelFactory_CreatesCorrectPlayerView() { PlayerViewModel result = ViewModelFactory.CreatePlayerViewModel(PlayerDataModel); Assert.AreEqual(PlayerDataModel.Id, result.Id); Assert.AreEqual(PlayerDataModel.Name, result.Name); }
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))); }
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))); }
public IEnumerable <PlayerViewModel> GetPlayers() { return(_context.Players.Select(p => ViewModelFactory.CreatePlayerViewModel(p))); }