public ApiListResult <ProductAttributeDTO> Get([FromUri] AntPageOption option = null) { var query = ProductAttributeService.GetAll().Where(x => !x.Deleted).ProjectTo <ProductAttributeDTO>(); if (option != null) { if (!string.IsNullOrEmpty(option.SortField)) { //for example if (option.SortField == "id") { if (option.SortOrder == PageSortTyoe.DESC) { query = query.OrderByDescending(x => x.Id); } else { query = query.OrderBy(x => x.Id); } } } if (option.Page > 0 && option.Results > 0) { if (string.IsNullOrEmpty(option.SortField)) { query = query.OrderBy(x => x.Id); } } } else { query = query.OrderBy(x => x.Id); } var count = query.Count(); var result = query.Paging <ProductAttributeDTO>(option.Page - 1, option.Results, count); return(new ApiListResult <ProductAttributeDTO>(result, result.PageIndex, result.PageSize, count)); }