public ActionResult Index(BookingFilterDTO filter) { ViewBag.Garages = garageRepository.FindAllAsQueryable(); ViewBag.Van = filter.Van; ViewBag.Date = filter.Date; List <DbBooking> bookings = GetFilteredBookings(filter); return(View(bookings.Select(i => new BookingDTO(i)).ToList())); }
// TODO move private List <DbBooking> GetFilteredBookings(BookingFilterDTO filter) { var bookings = bookingRepository.FindAllAsQueryable(i => i.GarageId == filter.GarageId); if (filter.Van) { bookings = bookings.Where(i => i.Type != Models.Enums.VehicleType.Car); } else { bookings = bookings.Where(i => i.Type == Models.Enums.VehicleType.Car); } if (filter.Date != null) { bookings = bookings.Where(i => i.StartDateTime.Date == filter.Date.Value.Date); } return(bookings.OrderByDescending(i => i.StartDateTime).ToList()); }