Пример #1
0
        public void ReturnCar(Guid rentalId, Guid carId, Guid driverId, DateTime finished)
        {
            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._unitOfWork.RentalRepository.Get(rentalId)
                            ?? throw new Exception($"Could not find rental '{rentalId}'");

            //change position of car
            this._positionService.CarPosition(car);
            //end rental (set finished time value, calculate cost and amount of free minutes)
            rental.ReturnCar(finished);
            //set car status to "free"
            car.MakeCarFree();
            //add calculated amount of free miutes to driver's account
            driver.AddFreeMinutes(rental.FreeMinutes);
            //change driver's balance
            driver.ChangeBalance(false, rental.Total);
            this._unitOfWork.Commit();
        }