/// <summary> /// Calculates the rate for each hotel and stores in dictionary. /// </summary> /// <returns></returns> public static Dictionary <string, OutputHotel> CalculateRateForEachHotel() { try { Console.WriteLine("Enter:\n1.If you are a REGULAR customer\n2.If you are a REWARDS customer"); int options = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the check-in date(DDMMMYYYY):"); DateTime checkinDate = DateTime.Parse(Console.ReadLine()); Console.WriteLine("Enter the check-out date(DDMMMYYYY):"); DateTime checkoutDate = DateTime.Parse(Console.ReadLine()); if (checkinDate > checkoutDate) { throw new HotelReservationCustomException(HotelReservationCustomException.ExceptionType.INVALID_DATE_RANGE, "CHECKOUT DATE MUST BE AHEAD OF CHECKIN DATE"); } Dictionary <string, OutputHotel> rateRecordsForRegularCustomer = new Dictionary <string, OutputHotel>(); Dictionary <string, OutputHotel> rateRecordsForRewardsCustomer = new Dictionary <string, OutputHotel>(); if (options == 1) { //UC 4 Refactor foreach (var v in hotelRecordsRegularCustomer) { int totalRate = 0; DateTime tempDate = checkinDate; while (tempDate <= checkoutDate) { //Checking if the day is weekend if (tempDate.DayOfWeek == DayOfWeek.Saturday || tempDate.DayOfWeek == DayOfWeek.Sunday) { totalRate += v.Value.weekendRate; } else { totalRate += v.Value.weekdayRate; } //Incrementing the current tempdate to next day tempDate = tempDate.AddDays(1); } //UC 6 Refactor OutputHotel outputHotel = new OutputHotel(v.Key, v.Value.ratings, totalRate); rateRecordsForRegularCustomer.Add(v.Value.hotelName, outputHotel); } return(rateRecordsForRegularCustomer); } else if (options == 2) { //UC 4 Refactor foreach (var v in hotelRecordsRewardsCustomer) { int totalRate = 0; DateTime tempDate = checkinDate; while (tempDate <= checkoutDate) { //Checking if the day is weekend if (tempDate.DayOfWeek == DayOfWeek.Saturday || tempDate.DayOfWeek == DayOfWeek.Sunday) { totalRate += v.Value.weekendRate; } else { totalRate += v.Value.weekdayRate; } //Incrementing the current tempdate to next day tempDate = tempDate.AddDays(1); } //UC 6 Refactor OutputHotel outputHotel = new OutputHotel(v.Key, v.Value.ratings, totalRate); rateRecordsForRewardsCustomer.Add(v.Value.hotelName, outputHotel); } return(rateRecordsForRewardsCustomer); } else { throw new HotelReservationCustomException(HotelReservationCustomException.ExceptionType.INVALID_CUSTOMER_TYPE, "INVALID CUSTOMER TYPE"); } } catch { throw new HotelReservationCustomException(HotelReservationCustomException.ExceptionType.INVALID_DATE_FORMAT, "INVALID DATE FORMAT"); } }
/// <summary> /// Calculates the rate for each hotel and stores in dictionary. /// </summary> /// <returns></returns> public static Dictionary <string, OutputHotel> CalculateRateForEachHotel(DateTime checkinDate, DateTime checkoutDate, CustomerType customerType) { try { if (checkinDate > checkoutDate) { throw new HotelReservationCustomException(HotelReservationCustomException.ExceptionType.INVALID_DATE_RANGE, "CHECKOUT DATE MUST BE AHEAD OF CHECKIN DATE"); } Dictionary <string, OutputHotel> rateRecordsForRegularCustomer = new Dictionary <string, OutputHotel>(); Dictionary <string, OutputHotel> rateRecordsForRewardsCustomer = new Dictionary <string, OutputHotel>(); if (customerType == CustomerType.REGULAR_CUSTOMER) { //UC 4 Refactor foreach (var v in hotelRecordsRegularCustomer) { int totalRate = 0; DateTime tempDate = checkinDate; while (tempDate <= checkoutDate) { //Checking if the day is weekend if (tempDate.DayOfWeek == DayOfWeek.Saturday || tempDate.DayOfWeek == DayOfWeek.Sunday) { totalRate += v.Value.weekendRate; } else { totalRate += v.Value.weekdayRate; } //Incrementing the current tempdate to next day tempDate = tempDate.AddDays(1); } //UC 6 Refactor OutputHotel outputHotel = new OutputHotel(v.Key, v.Value.ratings, totalRate); rateRecordsForRegularCustomer.Add(v.Value.hotelName, outputHotel); } return(rateRecordsForRegularCustomer); } else if (customerType == CustomerType.REWARDS_CUSTOMER) { //UC 4 Refactor foreach (var v in hotelRecordsRewardsCustomer) { int totalRate = 0; DateTime tempDate = checkinDate; while (tempDate <= checkoutDate) { //Checking if the day is weekend if (tempDate.DayOfWeek == DayOfWeek.Saturday || tempDate.DayOfWeek == DayOfWeek.Sunday) { totalRate += v.Value.weekendRate; } else { totalRate += v.Value.weekdayRate; } //Incrementing the current tempdate to next day tempDate = tempDate.AddDays(1); } //UC 6 Refactor OutputHotel outputHotel = new OutputHotel(v.Key, v.Value.ratings, totalRate); rateRecordsForRewardsCustomer.Add(v.Value.hotelName, outputHotel); } return(rateRecordsForRewardsCustomer); } else { throw new HotelReservationCustomException(HotelReservationCustomException.ExceptionType.INVALID_CUSTOMER_TYPE, "INVALID CUSTOMER TYPE"); } } catch { throw new HotelReservationCustomException(HotelReservationCustomException.ExceptionType.INVALID_DATE_FORMAT, "INVALID DATE FORMAT"); } }