コード例 #1
0
        public async  Task<TrainingCenterListViewModel> GetPagedListAsync(TrainingCenterSearchRequest request)
        {
            var trainingCenters = _trainingCenters.AsNoTracking().Include(a => a.Creator).Include(a => a.LasModifier).OrderBy(a => a.CreateDate).AsQueryable();

            if (request.State.HasValue())
            {
                trainingCenters = trainingCenters.Where(a => a.State == request.State);
                if (request.City.HasValue())
                    trainingCenters = trainingCenters.Where(a => a.City == request.City);
            }

            if (request.Term.HasValue())
                trainingCenters = trainingCenters.Where(a => a.CenterName.Contains(request.Term));

            var result = trainingCenters.ProjectTo<TrainingCenterViewModel>(_mappingEngine);


            var query = await result
                .Skip((request.PageIndex - 1)*10)
                .Take(10)
                .ToListAsync();

            return new TrainingCenterListViewModel { SearchRequest = request, TrainingCenters = query };
        }
コード例 #2
0
 public virtual async Task<ActionResult> ListAjax(TrainingCenterSearchRequest request)
 {
     var viewModel = await _trainingCenterService.GetPagedListAsync(request);
     if (viewModel.TrainingCenters == null || !viewModel.TrainingCenters.Any()) return Content("no-more-info");
     return PartialView(MVC.TrainingCenter.Views._ListAjax, viewModel);
 }