private IEnumerable <OrderViewModel> GetFilteredSales(IEnumerable <OrderViewModel> sales, OrderFilter filter) { var expression = filter.ToExpression(); var predicate = expression.Compile(); if (filter.ProductName != null) { sales = sales.Where(x => predicate(x.ProductName, filter.ProductName)); } if (filter.ClientName != null) { sales = sales.Where(x => predicate(x.ClientName, filter.ClientName)); } if (filter.Date != null) { sales = sales.Where(x => x.Date == filter.Date); } return(sales); }