public async Task <LoadResult> ReadModelsAsync(string filter, int pageSize, int pageIndex, Func <TestModel, object> sort, bool isDesc) { await Task.Delay(TimeSpan.FromSeconds(2)); IEnumerable <TestModel> resultModels = _models; if (string.IsNullOrWhiteSpace(filter) == false) { resultModels = resultModels.Where(m => m.Name.Contains(filter)); } if (isDesc) { resultModels = resultModels.OrderByDescending(sort); } else { resultModels = resultModels.OrderBy(sort); } var totalCount = resultModels.Count(); IEnumerable <TestModel> items = resultModels.Skip(pageIndex * pageSize).Take(pageSize); var result = new LoadResult { TotalCount = totalCount, Result = items }; return(result); }
public async Task <ILoadResult> LoadDataAsync(int pageIndex, int pageSize) { var collection = new Collection <TestModel>(_source.Skip(pageIndex * pageSize).Take(pageSize).ToList()); var result = new LoadResult { Result = collection, TotalCount = TotalCount }; await Task.Delay(TimeSpan.FromSeconds(2)); return(result); }