Exemplo n.º 1
0
        public void Book(int carId, DateTime start, DateTime end)
        {
            var car = _carRepository.FindById(carId);

            if (car == null)
            {
                throw new CarDoesNotExistsException(carId);
            }

            var bookings = _bookingRepository.GetBooking(car, start, end);

            if (bookings.Count > 0)
            {
                throw new CarIsAlreadyBookedException(carId, start, end);
            }

            var days = (int)Math.Ceiling((end - start).TotalDays);

            _bookingRepository.BookCar(car, start, end, car.Price.DailyPrice * days);
        }