public static TourDataFilter ConvertToDbValue(TourFilter tourFilter) { TourDataFilter result = new TourDataFilter { Skip = tourFilter.Skip, Take = tourFilter.Take, CountryUrl = tourFilter.CountryUrl, TourType = tourFilter.TourType.HasValue ? TourTypesEnumConverter.ConvertToDbValue(tourFilter.TourType.Value) : null }; return(result); }
public PageDataModel <TourDataModel> GetToursPage(TourDataFilter filter) { var filteredTours = _dbContext.Tours .Include(t => t.Country) .Include(t => t.TourImages) .OrderBy(t => t.Category) .ThenBy(t => t.Country) .ThenBy(t => t.Name) .Where(t => string.IsNullOrWhiteSpace(filter.TourType) || t.Category == filter.TourType) .Where(t => string.IsNullOrWhiteSpace(filter.CountryUrl) || t.Country.UrlName == filter.CountryUrl); var count = filteredTours.Count(); var pageCollection = filteredTours .Skip(filter.Skip) .Take(filter.Take) .AsNoTracking() .ToList(); var result = new PageDataModel <TourDataModel>(count, pageCollection); return(result); }