public async Task <JsonResult> GetPagedData(PagedAssetResultRequestDto input) { var p = GetPagedInput(); input.MaxResultCount = p.MaxResultCount; input.Sorting = p.Sorting; input.SkipCount = p.SkipCount; var output = await _fieldAppService.SearchAssetPagedResult(input); return(Json(new { total = output.TotalCount, rows = output.Items })); }
public async Task <PagedResultDto <AssetDto> > SearchAssetPagedResult(PagedAssetResultRequestDto input) { var query = _assetRepository.GetAllIncluding(x => x.Depot) .WhereIf(input.DepotId.HasValue, x => x.DepotId == input.DepotId.Value) .WhereIf(input.Category != null, x => x.Category == input.Category); var totalCount = await AsyncQueryableExecuter.CountAsync(query); if (!string.IsNullOrWhiteSpace(input.Sorting)) { query = query.OrderBy(input.Sorting); // Applying Sorting } query = query.Skip(input.SkipCount).Take(input.MaxResultCount); // Applying Paging var entities = await AsyncQueryableExecuter.ToListAsync(query); return(new PagedResultDto <AssetDto>( totalCount, ObjectMapper.Map <List <AssetDto> >(entities) )); }