public async Task <IActionResult> Index(ProductGroupSearchViewModel searchModel) { ViewBag.Parents = await _productGroupRepository.GetParentsAsync(); var model = await _productGroupRepository.LoadAsyncCount( this.CurrentPage, this.PageSize, searchModel); this.TotalNumber = model.Item1; ViewBag.SearchModel = searchModel; return(View(model.Item2)); }
public async Task <Tuple <int, List <ProductGroupDTO> > > LoadAsyncCount( int skip = -1, int take = -1, ProductGroupSearchViewModel model = null) { var query = Entities.ProjectTo <ProductGroupDTO>(); if (model.Id != null) { query = query.Where(x => x.Id == model.Id); } if (!string.IsNullOrEmpty(model.Title)) { query = query.Where(x => x.Title.Contains(model.Title)); } if (model.ParentId != null) { query = query.Where(x => x.ParentId == model.ParentId); } 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 <ProductGroupDTO> >(Count, await query.ToListAsync())); }