// A DI Framework may not compile this type of Injection as Parameter, so, you have to change this to non-static public static string OverlappingBookingsExist(Booking booking, IBookingStorage bookingStorage) { if (booking.Status == "Cancelled") { return(string.Empty); } var bookings = bookingStorage.GetActiveBookings(booking.Id); // We didn't get the logic below in a separate class because the implementation below is specific to the function here... var overlappingBooking = bookings.FirstOrDefault( b => booking.ArrivalDate < b.DepartureDate && b.ArrivalDate < booking.DepartureDate); /* * booking.ArrivalDate >= b.ArrivalDate * && booking.ArrivalDate < b.DepartureDate || booking.DepartureDate > b.ArrivalDate ||&& booking.DepartureDate <= b.DepartureDate ||These tests don't work correctly... */ return(overlappingBooking == null ? string.Empty : overlappingBooking.Reference); }
public static string OverlappingBookingsExist(Booking booking, IBookingStorage storage) { if (booking.Status == "Cancelled") { return(string.Empty); } var bookings = storage.GetActiveBookings(booking.Id); var overlappingBooking = bookings.FirstOrDefault( b => booking.ArrivalDate < b.DepartureDate && b.ArrivalDate < booking.DepartureDate); return(overlappingBooking == null ? string.Empty : overlappingBooking.Reference); }