/// <summary> /// Maps domain entity to presentation /// </summary> /// <param name="team"><see cref="Team"/> domain entity.</param> /// <param name="captain">Captain of the team.</param> /// <param name="roster">Roster of team's players.</param> /// <returns> View model object </returns> public static TeamViewModel Map(Team team, Player captain, IEnumerable <Player> roster) { var teamViewModel = new TeamViewModel { Id = team.Id, Name = team.Name, Coach = team.Coach, Achievements = team.Achievements }; if (captain != null) { teamViewModel.Captain = PlayerNameViewModel.Map(captain); } if (roster != null) { teamViewModel.Roster = new List <PlayerNameViewModel>(); foreach (var player in roster) { teamViewModel.Roster.Add(PlayerNameViewModel.Map(player)); } } return(teamViewModel); }
/// <summary> /// Returns list of free players which are satisfy specified search string, team and exclude list /// </summary> /// <param name="searchString">Name of player</param> /// <returns>List of free players</returns> public JsonResult GetFreePlayers(string searchString) { #pragma warning disable S1226 // Method parameters, caught exceptions and foreach variables' initial values should not be ignored searchString = HttpUtility.UrlDecode(searchString).Replace(" ", string.Empty); #pragma warning restore S1226 // Method parameters, caught exceptions and foreach variables' initial values should not be ignored var _freePlayersDto = _playerService.GetFreePlayerDto(). Where(p => (p.FirstName + p.LastName).Contains(searchString) || (p.LastName + p.FirstName).Contains(searchString)); var result = _freePlayersDto.OrderBy(p => p.LastName) #pragma warning disable S2971 // "IEnumerable" LINQs should be simplified Enity franework error must be ToList() .ToList() #pragma warning restore S2971 // "IEnumerable" LINQs should be simplified .Select(p => PlayerNameViewModel.Map(p)); return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Returns list of free players which are satisfy specified search string, team and exclude list /// </summary> /// <param name="searchString">Name of player</param> /// <param name="excludeList">list of players ids should be excluded from result</param> /// <param name="includeList">list of players ids should be included to result</param> /// <param name="includeTeam">Id of team which players should be included to the search result</param> /// <returns>List of free players</returns> public JsonResult GetFreePlayers(string searchString, string excludeList, string includeList, int?includeTeam) { searchString = HttpUtility.UrlDecode(searchString).Replace(" ", string.Empty); var query = _playerService.Get() .Where(p => (p.FirstName + p.LastName).Contains(searchString) || (p.LastName + p.FirstName).Contains(searchString)); if (includeTeam.HasValue) { if (string.IsNullOrEmpty(includeList)) { query = query.Where(p => p.TeamId == null || p.TeamId == includeTeam.Value); } else { var selectedIds = ParseIntList(includeList); query = query.Where(p => p.TeamId == null || p.TeamId == includeTeam.Value || selectedIds.Contains(p.Id)); } } else if (string.IsNullOrEmpty(includeList)) { query = query.Where(p => p.TeamId == null); } else { var selectedIds = ParseIntList(includeList); query = query.Where(p => p.TeamId == null || selectedIds.Contains(p.Id)); } if (!string.IsNullOrEmpty(excludeList)) { var selectedIds = ParseIntList(excludeList); query = query.Where(p => !selectedIds.Contains(p.Id)); } var result = query.OrderBy(p => p.LastName) .ToList() .Select(p => PlayerNameViewModel.Map(p)); return(Json(result, JsonRequestBehavior.AllowGet)); }