public async Task <IActionResult> Index(NewsGroupSearchViewModel searchModel) { var model = await _newsGroupRepository.LoadAsyncCount( this.CurrentPage, this.PageSize, searchModel); this.TotalNumber = model.Item1; ViewBag.SearchModel = searchModel; return(View(model.Item2)); }
public async Task <Tuple <int, List <NewsGroupDTO> > > LoadAsyncCount( int skip = -1, int take = -1, NewsGroupSearchViewModel model = null) { var query = Entities.ProjectTo <NewsGroupDTO>(); 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)); } 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 <NewsGroupDTO> >(Count, await query.ToListAsync())); }