public async Task <IActionResult> Index(int Id, ProductGroupFeatureSearchViewModel searchModel = null) { ViewBag.ProductGroup = await _productGroupRepository.GetByIdAsync(Id); var model = await _productGroupFeatureRepository.LoadAsyncCount(Id, this.CurrentPage, this.PageSize, searchModel); this.TotalNumber = model.Item1; ViewBag.SearchModel = searchModel; return(View(model.Item2)); }
public async Task <Tuple <int, List <ProductGroupFeatureDTO> > > LoadAsyncCount( int productGroupId, int skip = -1, int take = -1, ProductGroupFeatureSearchViewModel model = null) { var query = (from productGroupFeature in this.DbContext.ProductGroupFeature where productGroupFeature.ProductGroupId == productGroupId join feature in this.DbContext.Feature on productGroupFeature.FeatureId equals feature.Id orderby productGroupFeature.Id select new ProductGroupFeatureDTO { Id = productGroupFeature.Id, ProductGroupId = productGroupId, FeatureId = feature.Id, FeatureTitle = feature.Title }); if (!string.IsNullOrEmpty(model.FeatureTitle)) { query = query.Where(x => x.FeatureTitle.Contains(model.FeatureTitle)); } int Count = query.Count(); query = query.OrderByDescending(x => x.Id); if (skip != -1) { query = query.Skip((skip - 1) * take); } if (take != -1) { query = query.Take(take); } return(new Tuple <int, List <ProductGroupFeatureDTO> >(Count, await query.ToListAsync())); }