Beispiel #1
0
        public ActionResult SearchFootballPlayer(string searchText, int?teamId)
        {
            SearchFootballPlayerViewModel filter = new SearchFootballPlayerViewModel();

            filter.TeamId     = teamId.GetValueOrDefault();
            filter.SearchText = searchText;
            if (!string.IsNullOrEmpty(searchText))
            {
                filter.FoundPlayers = _adminService.GetSearchResults(filter);
            }

            return(View(filter));
        }
Beispiel #2
0
        public List <FootballTeamPlayerViewModel> GetSearchResults(SearchFootballPlayerViewModel filter)
        {
            Expression <Func <FootballPlayer, bool> > teamSearchExpression = t => true;

            if (filter.TeamId > 0)
            {
                teamSearchExpression = h => h.TeamsHistory.All(a => a.TeamId != filter.TeamId || (a.TeamId == filter.TeamId && a.EndDate != null));
            }

            var players = UnitOfWork.FootballPlayers.Where(teamSearchExpression).ToList();

            return(players.Where(
                       x =>
                       x.FirstName.Contains(filter.SearchText) ||
                       (x.SecondName != null && x.SecondName.Contains(filter.SearchText)) ||
                       x.LastName.Contains(filter.SearchText))
                   .AsQueryable()
                   .ProjectTo <FootballTeamPlayerViewModel>()
                   .ToList());
        }