/// <summary> /// Gets players /// </summary> /// <returns> Player list. </returns> public ICollection <PlayerViewModel> GetPlayers() { var result = _playerService.Get() .Select(p => PlayerViewModel.Map(p)); return(result.ToList()); }
public void Map_DomainPlayerAsParam_MappedToViewModel() { // Arrange var testViewModel = new PlayerMvcViewModelBuilder() .WithId(1) .WithFirstName("FirstName") .WithLastName("LastName") .WithBirthYear(1983) .WithHeight(186) .WithWeight(95) .WithTeamId(1) .Build(); var testDomainModel = new PlayerBuilder(1, "FirstName", "LastName") .WithBirthYear(1983) .WithHeight(186) .WithWeight(95) .Build(); // Act var actual = PlayerViewModel.Map(testDomainModel); // Assert Assert.Equal(testViewModel, actual, new PlayerViewModelComparer()); }
private IHttpActionResult AssignTeamToPlayer(Player playerToUpdate, Uri link) { int teamId; try { teamId = WebApiHelpers.GetKeyFromUri <int>(Request, link); _teamService.Get(teamId); playerToUpdate.TeamId = teamId; _playerService.Edit(playerToUpdate); } catch (MissingEntityException ex) { ModelState.AddModelError(string.Format("{0}.{1}", CONTROLLER_NAME, ex.Source), ex.Message); return(BadRequest(ModelState)); } catch (InvalidOperationException ex) { ModelState.AddModelError(string.Format("{0}.{1}", CONTROLLER_NAME, ex.Source), ex.Message); return(BadRequest(ModelState)); } var player = PlayerViewModel.Map(playerToUpdate); return(Ok(player)); }
/// <summary> /// Gets roster of the team. /// </summary> /// <param name="key">Id of the team.</param> /// <returns>Players in team roster.</returns> public IEnumerable <PlayerViewModel> GetPlayers(int key) { var result = _teamService .GetTeamRoster(new TeamId(key)) .Select(p => PlayerViewModel.Map(p)); return(result); }
/// <summary> /// The get player. /// </summary> /// <param name="key"> The key. </param> /// <returns> The <see cref="SingleResult"/>. </returns> public PlayerViewModel Get(int key) { var result = _playerService .Get() .Where(p => p.Id == key) .Select(p => PlayerViewModel.Map(p)) .First(); return(result); }
/// <summary> /// Edit player action (GET) /// </summary> /// <param name="id">Player id</param> /// <returns>View to edit specific player</returns> public ActionResult Edit(int id) { var player = _playerService.Get(id); if (player == null) { return(HttpNotFound()); } var playerViewModel = PlayerViewModel.Map(player); return(View(playerViewModel)); }
/// <summary> /// Maps domain entity to presentation /// </summary> /// <param name="user"><see cref="User"/> domain entity.</param> /// <returns> View model object </returns> public static UserViewModel Map(User user) { var userViewModel = new UserViewModel { Id = user.Id, Name = user.UserName, Email = user.Email, PersonName = user.PersonName, Phone = user.PhoneNumber, IsBlocked = user.IsBlocked, LoginProviders = user.LoginProviders, Roles = user.Roles }; if (user.Player != null) { userViewModel.Player = PlayerViewModel.Map(user.Player); } return(userViewModel); }