コード例 #1
0
        public static ReceiptModel Calculate(decimal dayRate, ParkingTimeModel parkingTime)
        {
            var calenderDays = parkingTime.GetCalendarDaysParked();
            var price        = dayRate * (decimal)calenderDays;

            return(new ReceiptModel()
            {
                RateName = string.Format("Day Rate - {0} Calendar Day(s)", calenderDays),
                Details = parkingTime,
                Price = price,
            });
        }
コード例 #2
0
        public static ReceiptModel GetRates(DateTime entry, DateTime exit)
        {
            var rates = ParkingRatesProvider.GetRates();

            var times = new ParkingTimeModel()
            {
                Entry = entry,
                Exit  = exit,
            };

            return(rates.Calculate(times));
        }
コード例 #3
0
        public static ReceiptModel Calculate(this IEnumerable <StandardRatePriceModel> rates, ParkingTimeModel parkingTime)
        {
            // the order of the rules dictates which one should be chosen
            // if there are multiple matches, ie take the first one
            var match = rates
                        .OrderBy(r => r.UpToHours)
                        .Where(r => r.IsMatch(parkingTime))
                        .FirstOrDefault();

            return(match == null
                ? null
                : new ReceiptModel()
            {
                RateName = string.Format("Standard Rate Up To {0} Hour(s)", match.UpToHours),
                Details = parkingTime,
                Price = match.Price,
            });
        }