// Calculates the rental price for a reservation when car has been returned
        /// <summary>
        /// The formula for calculating the rental cost is:
        /// baseDayRentalPrice * numberOfDays * baseDayRentalModifier + kmPrice * numberOfKm * kmPriceModifier
        /// Preconditions: The given ActivatedReservation must be deactivated before calling this method.
        /// Calculates the rental price for a reservation.
        /// </summary>
        /// <param name="activatedReservationId"></param>
        /// <returns>The total cost of the rental</returns>
        public async Task <double> calculateCost(int activatedReservationId)
        {
            await checkRentalRates();

            service = new DatabaseAccessService(context);

            var activatedReservation = await service.getActivatedReservation(activatedReservationId);

            if (activatedReservation == null)
            {
                throw new ArgumentException("No ActivatedReservation with given id exists");
            }

            var rentedCar = await service.getRentalCar(activatedReservation.rentedCar.carNumber);

            var carType = rentedCar.rentalCarType;

            var dayDiff = (activatedReservation.reservation.expectedReturnDate
                           - activatedReservation.reservation.rentalDate).Days;
            var mileage = activatedReservation.endMileage - activatedReservation.startMileage;

            double price = baseDayRental * dayDiff * carType.basePriceModifier
                           + kmPrice * mileage * carType.kmPriceModifier;

            return(price);
        }
        /// <summary>
        /// The formula for calculating the rental cost is:
        /// baseDayRentalPrice * numberOfDays * baseDayRentalModifier + kmPrice * numberOfKm * kmPriceModifier
        /// Use this to change baseDayRentalPrice and kmPrice variables.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="baseDayRentalPrice"></param>
        /// <param name="kmPrice"></param>
        /// <returns></returns>
        public async static Task setRentalRate(CarRentalContext context, double baseDayRentalPrice, double kmPrice)
        {
            var service = new DatabaseAccessService(context);
            await service.setBaseDayRentalPrice(baseDayRentalPrice);

            await service.setKmPrice(kmPrice);
        }
Exemplo n.º 3
0
 public CarReservationService()
 {
     context = new CarRentalContext();
     db      = new DatabaseAccessService(context);
 }
Exemplo n.º 4
0
 public CarReservationService(CarRentalContext context)
 {
     this.context = context;
     db           = new DatabaseAccessService(context);
 }
 public RentalRateCalculatorService()
 {
     context = new CarRentalContext();
     service = new DatabaseAccessService(context);
 }
 public RentalRateCalculatorService(CarRentalContext context)
 {
     this.context = context;
     service      = new DatabaseAccessService(context);
 }