I want to the user to filter a list of receipts by various criteria. Just the regular, an empty filter should show all items, an entry in customer should show all receipts from that customer and an additional entry in date should show all entries from said customer on the given date. I have the feeling, my if else apprach is not the best way, since with 4 criteria I'm already at 16 branches, not speak of 5, 6, or 7 criteria.
What is the most elegant way to achieve this.
Model:
class customer
{
public int ID { get; set; }
public string Name { get; set; }
}
class receipt
{
public int ID { get; set; }
public string Number { get; set; }
public DateTime Date { get; set; }
public double Amount { get; set; }
public customer Customer { get; set; }
}
Viewmodel
class receiptViewModel
{
ObservableCollection<receipt> ReceiptList { get; set; }
List<receipt> ReceiptListView { get; set; }
private string filter;
public string Filter
{
get { return filter; }
set
{
filter = value;
if (number != null && date == null && customer && null)
{
ReceiptListView = ReceiptList.Where(x => x.Number.Contains(number)).ToList();
}
else if (number != null && date != null && customer && null)
{
ReceiptListView = ReceiptList.Where(x => x.Number.Contains(number) && x.Date === date).ToList();
}
//aso aso aso
}
}