public ActionResult <IEnumerable <Sale> > GetSales(DateTime?startDate = null, DateTime?endDate = null) { var items = _repository.Filter(x => (!startDate.HasValue && !endDate.HasValue) || (!startDate.HasValue && endDate.HasValue && x.SalesDate <= endDate.Value) || (startDate.HasValue && !endDate.HasValue && x.SalesDate >= startDate.Value) || (startDate.HasValue && endDate.HasValue && x.SalesDate <= endDate.Value && x.SalesDate >= startDate.Value)); if (items != null && items.Count() > 0) { return(Ok(items)); } else { return(NotFound()); } }