public List <Expense> GetExpenses(int userId, string searchString, DateTime?startDate, DateTime?endDate) { //What the query does?? //Selects the expenses based on current user session //searches the database based on item and category if search string is not null var expense = _expenseRepository.FindBy(x => x.CreatedBy == userId && (searchString == null || (x.Item + x.Categories.Name).Contains(searchString)) && (startDate == null || x.Date >= startDate) && (endDate == null || x.Date <= endDate)) .OrderByDescending(x => x.Id).Select(x => new Expense { Id = x.Id, Amount = x.Amount, CategoryId = x.CategoryId, CreatedAt = x.CreatedAt, CreatedBy = x.CreatedBy, Date = x.Date, Description = x.Description, Item = x.Item, ModifiedAt = x.ModifiedAt, CategoryName = x.Categories.Name }).ToList(); return(expense); }