public async Task<TitleListViewModel> GetPagedList(TitleSearchRequest request) { var titles = _titles.AsNoTracking().Include(a => a.Creator).Include(a => a.LasModifier).OrderByDescending(a => a.CreateDate).AsQueryable(); if (request.Name.HasValue()) titles = titles.Where(a => a.Name.Contains(request.Name)); if ((int)request.Type != 0) titles = titles.Where(a => a.Type == request.Type); if ((int)request.Category != 0 && request.Type==TitleType.CourseContent) titles = titles.Where(a => a.Category == request.Category); var selectedTitles = titles.ProjectTo<TitleViewModel>(_mappingEngine); var query = await selectedTitles .Skip((request.PageIndex - 1)*10) .Take(10) .ToListAsync(); return new TitleListViewModel { Request = request, Titles = query }; }
public virtual async Task<ActionResult> ListAjax(TitleSearchRequest request) { var viewModel = await _titleService.GetPagedList(request); if (viewModel.Titles == null || !viewModel.Titles.Any()) return Content("no-more-info"); return PartialView(MVC.Title.Views._ListAjax, viewModel); }