public void ListFlights_OrderByDepartureDate() { var searchParams = new BookingSearchParams(); var flightList = _bookingService.SearchFlights(searchParams); Assert.AreEqual("0002", flightList[1].FlightNumber); Assert.AreEqual("0003", flightList[7].FlightNumber); }
public void ListFlights_DestinedForLAX() { var searchParams = new BookingSearchParams { ArrivalAirportCode = "LAX" }; var flightList = _bookingService.SearchFlights(searchParams); Assert.AreEqual(2, flightList.Count); }
public void ListFlight_CheckCancellation() { var searchParams = new BookingSearchParams(); _bookingService.UpdateStatus("0001", FlightStatus.Cancelled); var flightList = _bookingService.SearchFlights(searchParams); var cancelledFlightCount = flightList.Count(f => f.FlightStatus == FlightStatus.Cancelled); Assert.AreEqual(1, cancelledFlightCount); }
// // GET: /Booking/ public ActionResult Index() { // TODO Setup some sort of DI and inject this, to remove EF reference and east testing MonarchContext context = new MonarchContext(); BookingService service = new BookingService(context); var vm = new IndexViewModel(); vm.FullFlightList = service.GetAllFlights(); BookingSearchParams bsp = new BookingSearchParams { ArrivalAirportCode = "LAX" }; vm.SearchResults = service.SearchFlights(bsp); return(View(vm)); }
public List <Flight> SearchFlights(BookingSearchParams parameters) { IQueryable <Flight> query = _context.Flights.OrderBy(f => f.DepartureTime); //TODO Impliment this if a sort by options is given to the user // if (paramaters.OrderByDepartureTime) // query = query.OrderBy(f => f.DepartureTime); if (!parameters.IncludeFlightsAtCapacity) { query = query.Where(f => f.SeatsBooked < f.SeatsOnFlight); } if (!string.IsNullOrEmpty(parameters.ArrivalAirportCode)) { query = query.Where(f => f.ArrivalAirportCode == parameters.ArrivalAirportCode); } return(query.ToList()); }
public async Task <IEnumerable <Model.Booking> > Search(BookingSearchParams bookingSearchParams) { var bookings = _context.Bookings.AsNoTracking().OrderByDescending(h => h.Id).AsQueryable(); if (bookingSearchParams.HotelId != 0) { bookings = bookings.Where(b => b.HotelId == bookingSearchParams.HotelId); } if (bookingSearchParams.CustomerName != null) { bookings = bookings.Where(b => b.CustomerName.ToLower().Contains(bookingSearchParams.CustomerName.ToLower())); } //** Between check in and check out date..... if (bookingSearchParams.CheckIn != DateTime.MinValue && bookingSearchParams.CheckOut != DateTime.MinValue) { bookings = bookings.Where(b => b.CheckIn >= bookingSearchParams.CheckIn && b.CheckOut <= bookingSearchParams.CheckOut); } return(await PagedList <Model.Booking> .CreateAsync(bookings, bookingSearchParams.PageNumber, bookingSearchParams.PageSize)); }
// Search: api/booking/HotelId=2" public async Task <IActionResult> SearchBooking([FromQuery] BookingSearchParams bookingSearchParams) { var bookings = await _repo.Search(bookingSearchParams); return(Ok(bookings)); }