public GetHorseAdListResults SearchAfter(SearchHorseDao searchQuery, int pageNumber) { var skipNumber = GetNumberToSkip(pageNumber); var searchPredicate = searchQuery.GetSearchPredicate(); var orderProperty = searchQuery.GetOrderProperty(); var isAscendingSortOrder = searchQuery.IsAscendingSortOrder(); var horseAds = _ctx.HorseAds.AsQueryable().AsExpandable().Where(searchPredicate); var results = new GetHorseAdListResults() { TotalCount = horseAds.Count(), HorseAdList = isAscendingSortOrder ? horseAds.AsEnumerable().OrderBy(x => orderProperty.GetValue(x, null)).Skip(skipNumber).Take(ApplicationConstants.AdsPerPage).ToList() : horseAds.AsEnumerable().OrderByDescending(x => orderProperty.GetValue(x, null)).Skip(skipNumber).Take(ApplicationConstants.AdsPerPage).ToList() }; return(results); }
public GetHorseAdListResultsDTO SearchHorses(HorseAdSearchViewModel searchViewModel) { SearchModelDao searchModelDao = UtilConverter.FromSearchModelToSearchModelDao(searchViewModel); var sortAfterValues = Enum.GetValues(typeof(SortAfterEnum)); switch (searchModelDao.SortAfter) { case (int)SortAfterEnum.Age: searchModelDao.SortAfterString = SortAfterEnum.Age.ToString(); break; case (int)SortAfterEnum.Height: searchModelDao.SortAfterString = SortAfterEnum.Height.ToString(); break; case (int)SortAfterEnum.Price: searchModelDao.SortAfterString = SortAfterEnum.Price.ToString(); break; case (int)SortAfterEnum.Views: searchModelDao.SortAfterString = SortAfterEnum.Views.ToString(); break; default: searchModelDao.SortAfterString = SortAfterEnum.DatePosted.ToString(); break; } if (searchModelDao.SortDirection != 1 && searchModelDao.SortDirection != 0) { searchModelDao.SortDirection = 1; } SearchHorseDao searchQuery = new SearchHorseDao(searchModelDao); var matchHorses = _iHorseAdDao.SearchAfter(searchQuery, searchViewModel.PageNumber); return(HorseAdConverter.ConvertHorseListResult(matchHorses)); }