示例#1
0
        public async Task <decimal> CalculateFinalPriceAsync()
        {
            if (_carType == null || _settings == null)
            {
                using (var db = new CarRentalDatabase())
                {
                    _carType = _carType ?? await db.CarTypes.FirstOrDefaultAsync(x => x.Id == CarTypeId);

                    _settings = _settings ?? await db.Settings.FirstOrDefaultAsync();
                }
            }

            var days    = (int)Math.Ceiling(DateTo.Subtract(DateFrom).TotalDays) + 1;
            var mileage = FinalMileage - InitialMileage;

            return(_carType.DayMultiplier * days * _settings.DayPrice
                   + _carType.KilometerMultiplier * mileage * _settings.KilometerPrice);
        }