public Models.ui.BookingConfirmUI CreateBooking(Models.ui.BookingCreateUI car, int userId) { var result = new BookingConfirmUI(); var supplierObj = new SupplierBObj(); var carObj = new CarBObj(supplierObj); var booking = new BookingBObj(carObj, supplierObj); var startDate = car.fromDate; var endDate = car.toDate; var car_reg = car.car_reg; var carId = db.getCarIdByReg(car_reg); Car carDb = db.getCar(carId); carObj.setId(carId); carObj.setDailyRate(carDb.cost_per_day); booking.setBookingRange(startDate, endDate); var dbUnavailabilities = db.listUnavailabilitiesForCar(carId); var unavailabilities = new List<UnavailableDateBObj>(); foreach (var u in dbUnavailabilities) { var unavailable = new UnavailableDateBObj { fromDate = u.start_date, toDate = u.end_date }; unavailabilities.Add(unavailable); } car.valid = booking.valid(unavailabilities); if (car.valid) { car.amount = booking.getTotalCost(); UnavailableDateBObj date = booking.create(); var customer_id = userId; result.BookingId = db.createNewBooking(customer_id, carId, startDate, endDate); } result.CarReg = car_reg; result.Cost = booking.getTotalCost(); return result; }
public void Booking_should_create_and_return_an_UnavailableDateBObj() { DateTime pickupDate = new DateTime(2012, 12, 31); var car = new CarBObj(new SupplierBObj()); car.setDailyRate(50); var booking = BookingBObj.newBooking(car); booking.setBookingRange(pickupDate, 10); var unavailable = new UnavailableDateBObj { fromDate = pickupDate, toDate = pickupDate.AddDays(10) }; var customer = new CustomerBObj(); customer.setId(1); booking.setCustomer(customer); car.setId(1); var takenDates = new List<UnavailableDateBObj>(); Assert.AreEqual(booking.create().ToString() , unavailable.ToString() ); }
public Models.ui.BookingCreateUI ShowChosenCar(BookingCreateUI car) { var supplierObj = new SupplierBObj(); var carObj = new CarBObj(supplierObj); var booking = new BookingBObj(carObj, supplierObj); var startDate = car.fromDate; var endDate = car.toDate; var car_reg = car.car.car_reg; var carId = db.getCarIdByReg(car_reg); carObj.setId(carId); booking.setBookingRange(startDate, endDate); var dbUnavailabilities = db.listUnavailabilitiesForCar(carId); var unavailabilities = new List<UnavailableDateBObj>(); foreach (var u in dbUnavailabilities) { var unavailable = new UnavailableDateBObj{ fromDate = u.start_date, toDate = u.end_date }; unavailabilities.Add(unavailable); } car.valid = booking.valid(unavailabilities); car.amount = booking.getTotalCost(); return car; }
public void Booking_should_not_be_valid_if_car_unavailable_before_and_during_period() { DateTime pickupDate = new DateTime(2012, 12, 31); DateTime alreadyTakenDateBefore = new DateTime(2012,11,10); DateTime alreadyTakenDateAfter = new DateTime(2013, 02, 10); DateTime alreadyTakenDateDuring = new DateTime(2013, 01, 04); var car = new CarBObj(new SupplierBObj()); car.setDailyRate(50); var booking = BookingBObj.newBooking(car); booking.setBookingRange(pickupDate, 10); var customer = new CustomerBObj(); customer.setId(1); booking.setCustomer(customer); car.setId(1); var takenDates = new List<UnavailableDateBObj>(); var unavailability = new UnavailableDateBObj { fromDate = alreadyTakenDateBefore, toDate = alreadyTakenDateDuring }; takenDates.Add(unavailability); Assert.IsFalse(booking.valid(takenDates)); }