private static IQueryable <Expense> AddFiltersOnQueryable(GetAllExpensesFilter expensesFilter, IQueryable <Expense> queryable) { if (expensesFilter.Value != null) { queryable = queryable.Where(x => Math.Abs(x.Value - expensesFilter.Value) < 0.1); } return(queryable); }
public async Task <List <Expense> > GetExpensesAsync(GetAllExpensesFilter expensesFilter = null, PaginationFilter paginationFilter = null, string userId = null) { var queryable = _dataContext.Expenses.AsQueryable(); queryable = AddFiltersOnQueryable(expensesFilter, queryable); if (paginationFilter == null) { return(await queryable.Include(x => x.Tags).ToListAsync()); } if (userId != null) { queryable = queryable.Where(x => x.UserId == userId); } var skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize; return(await queryable.Include(x => x.Tags).Skip(skip).Take(paginationFilter.PageSize).ToListAsync()); }