示例#1
0
        public void StartRental(Guid rentalId, Guid carId, Guid driverId, DateTime startTime)
        {
            var car = this._uoW.CarRepository.Get(carId);

            if (car == null)
            {
                throw new Exception("There is no car with this Id");
            }

            var driver = this._uoW.DriverRepository.Get(driverId);

            if (driver == null)
            {
                throw new Exception("There is no driver with this Id");
            }

            var rental = this._rentalFactory.Create(rentalId, car, driver, startTime);

            IFreeMinutesPolicy policy = this._policyFactory.Create(driver);

            driver.RegisterPolicy(policy);

            car.Rent();

            this._uoW.RentalRepository.Insert(rental);
            this._uoW.Commit();
        }
示例#2
0
        public void MakeRental(Guid rentalId, Guid carId, Guid driverId, DateTime started)
        {
            Car car = this._unitOfWork.CarRepository.Get(carId)
                      ?? throw new Exception($"Could not find the car: '{carId}'");
            Driver driver = this._unitOfWork.DriverRepository.Get(driverId)
                            ?? throw new Exception($"Could not find the driver: '{driverId}'");

            Rental rental = this._rentalFactory.Create(rentalId, started, driver, car);

            IFreeMinutesPolicy policy = this._freeMinutespolicyFactory.Create(rental);

            //Register free minutes policy in rental object
            rental.RegisterPolicy(policy);
            // set car status to "rented"
            car.MakeCarRented();

            this._unitOfWork.RentalRepository.Insert(rental);
            this._unitOfWork.Commit();
        }
示例#3
0
        public void StopRental(Guid rentalId, Guid vehicleId, Guid driverId, DateTime stop)
        {
            Vehicle vehicle = this._unitOfWork.CarRepository.Get(vehicleId);

            if (vehicle == null)
            {
                vehicle = this._unitOfWork.ScooterRepository.Get(vehicleId)
                          ?? throw new Exception($"Could not find vehicle '{vehicleId}'.");
            }

            Driver driver = this._unitOfWork.DriverRepository.Get(driverId)
                            ?? throw new Exception($"Could not find driver '{driverId}'.");
            Rental rental = this._unitOfWork.RentalRepository.Get(rentalId)
                            ?? throw new Exception($"Could not find rental '{rentalId}'.");

            rental.StopRental(stop, vehicle.UnitPrice);
            vehicle.FreeUpVehicle();

            IFreeMinutesPolicy policy = this._freeMinutesFactory.Create(rental);

            driver.RegisterPolicy(policy, rental);

            this._unitOfWork.Commit();
        }
示例#4
0
 public void RegisterPolicy(IFreeMinutesPolicy policy)
 {
     _freeMinutesPolicy = policy;
 }
 public void RegisterPolicy(IFreeMinutesPolicy policy, Rental rental)
 {
     this._policy = policy ?? throw new ArgumentNullException("Empty free minutes policy");
     FreeMinutes  = policy.CalculateFreeMinutes(rental.Total, rental.GetTimeInMinutes());
 }
示例#6
0
 public void RegisterPolicy(IFreeMinutesPolicy policy)
 {
     this._policy = policy ?? throw new Exception("Empty free minutes policy");
 }