/// <summary> /// Method that is used to get the cheapest hotel for a Booking request /// </summary> /// <param name="bookingRequest">Booking request object that contains customer type and dates</param> /// <param name="hotels">List of hotels</param> /// <returns></returns> public static HotelBooking GetCheapestHotel(BookingRequest bookingRequest, IList <Hotel> hotels) { return(hotels .Select(hotel => GetHotelBooking(hotel, bookingRequest)) .OrderBy(h => h, new PriceComparer()) .FirstOrDefault()); }
/// <summary> /// builds a single booking request, that is used to mount the object /// </summary> /// <param name="input">String that describes a booking request</param> /// <returns>an object of a booking request</returns> public static BookingRequest BuildBookingRequest(string input) { BookingRequest bookingRequest = new BookingRequest(); string[] result; // split by : result = input.Split(":", StringSplitOptions.None); foreach (string item in result) { if (item == "Regular") { bookingRequest.CustomerType = "Regular"; } else if (item == "Rewards") { bookingRequest.CustomerType = "Rewards"; } else { bookingRequest.Dates = GetListOfDates(item); } } return(bookingRequest); }
/// <summary> /// This method is used to generate a list of booking requests, /// that will be used to process the cheapest hotel for that request /// </summary> /// <param name="input">List of booking request strings</param> /// <returns>list of bookingRequest objects</returns> public static IList <BookingRequest> BuildSearchRequest(IList <string> input) { List <BookingRequest> requests = new List <BookingRequest>(); foreach (string line in input) { BookingRequest bookingRequest = BuildBookingRequest(line); requests.Add(bookingRequest); } return(requests); }
/// <summary> /// Method that calculates hotel price for a sequence of dates /// </summary> /// <param name="hotel">object that describes a hotel</param> /// <param name="request">request that contains a list of dates and customer type</param> /// <returns></returns> public static HotelBooking GetHotelBooking(Hotel hotel, BookingRequest request) { double hotelPrice = 0d; foreach (var date in request.Dates) { bool isWeekend = WeekDay.sun == date || WeekDay.sat == date; bool isRewards = request.CustomerType == "Rewards"; hotelPrice += hotel.GetHotelCostByDay(isWeekend, isRewards); } return(new HotelBooking() { Hotel = hotel, Cost = hotelPrice }); }