public Task <QueryResult <Customer> > QueryAsync(CustomerQuery query) { // filter var filteredResults = CustomerList.Where(c => query.Filter.MinAge == null || c.Age >= query.Filter.MinAge).ToList(); var totalEntities = filteredResults.Count; // sort IEnumerable <Customer> orderedResult; switch (query.SortBy.SortType) { case SortTypes.Ascending: switch (query.SortBy.PropertyName) { case CustomerSortProperties.Age: orderedResult = filteredResults.OrderBy(c => c.Age); break; case CustomerSortProperties.Name: orderedResult = filteredResults.OrderBy(c => c.Name); break; case null: orderedResult = filteredResults; break; default: throw new ArgumentOutOfRangeException(); } break; case SortTypes.Descending: switch (query.SortBy.PropertyName) { case CustomerSortProperties.Age: orderedResult = filteredResults.OrderByDescending(c => c.Age); break; case CustomerSortProperties.Name: orderedResult = filteredResults.OrderByDescending(c => c.Name); break; case null: orderedResult = filteredResults; break; default: throw new ArgumentOutOfRangeException(); } break; case SortTypes.None: orderedResult = filteredResults; break; default: throw new ArgumentOutOfRangeException(); } // pagination var resultEntities = ClipToPagination(orderedResult, query.Pagination); var result = new QueryResult <Customer> { Entities = resultEntities, TotalCountOfEnties = totalEntities }; return(Task.FromResult(result)); }
// copy constructor public CustomerQuery(CustomerQuery customerQuery) : base(customerQuery) { }