public PageContainer GetPage(string category, int page, string search, string sort, FilterVM filter) { int entitiesPerPage = 10; PageContainer container = new PageContainer(); IEnumerable <TEntity> ads = dbSet.Where(ad => ad.IsFreezed == false); // search ads = dbSet.Where(ad => ad.Title.Contains(search)); // filter IFilterAdsStrategy <TEntity> filterAds = null; if (filter != null) { if (category == "smartphone") { filterAds = new FilterSmartphones <TEntity>(); } else if (category == "laptop") { filterAds = new FilterLaptops <TEntity>(); } else if (category == "monitor") { filterAds = new FilterMonitors <TEntity>(); } else if (category == "videocard") { filterAds = new FilterVideocards <TEntity>(); } else if (category == "processor") { filterAds = new FilterProcessors <TEntity>(); } else if (category == "RAM") { filterAds = new FilterRAMs <TEntity>(); } else if (category == "drive") { filterAds = new FilterDrives <TEntity>(); } } if (filterAds != null) { ads = filterAds.Filter(ads, filter); } // sort if (sort == "recent") { ads = ads.OrderByDescending(ad => ad.Id); } else if (sort == "decrease-price") { ads = ads.OrderByDescending(ad => ad.Price); } else if (sort == "increase-price") { ads = ads.OrderBy(ad => ad.Price); } else if (sort == "own") { ads = ads.Where(ad => ad.UserId == filter.UserId); } // pagination container.Ads = ads.Skip((page - 1) * entitiesPerPage).Take(entitiesPerPage); container.PageAmount = (int)Math.Ceiling(ads.Count() / (double)entitiesPerPage); return(container); }