Exemplo n.º 1
0
        public static bool IsMatch(this FlatRatePriceModel rate, ParkingTimeModel parkingTimes)
        {
            var entryMatch    = rate.EntryTimeRange.MatchesHourRange(parkingTimes.Entry);
            var exitMatch     = rate.ExitTimeRange.MatchesHourRange(parkingTimes.Exit);
            var exitRuleMatch = rate.PassesExitTimeRule(parkingTimes);

            return(entryMatch && exitMatch && exitRuleMatch);
        }
Exemplo n.º 2
0
        public static bool PassesExitTimeRule(this FlatRatePriceModel rate, ParkingTimeModel parkingTimes)
        {
            switch (rate.ExitTimeRule)
            {
            case TimeRangeRule.SAMEDAY:
                return(parkingTimes.Entry.Date == parkingTimes.Exit.Date);

            case TimeRangeRule.SAMEORNEXTDAY:
                return(parkingTimes.Entry.Date == parkingTimes.Exit.Date || parkingTimes.Entry.AddDays(1).Date == parkingTimes.Exit.Date);

            default:
                return(true);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the price for parking based on the rates provided and the time the customer was parked.
        /// The customer's parking times will be matched against the rules for rates and the best one will be used to calculate a price
        /// </summary>
        /// <param name="rates">Rates should be in preferred order, if there is overlap then the first match will be used.
        /// Flat rates get precedence over standard rates.</param>
        /// <param name="parkingTime">The start and end times of the parking event</param>
        /// <returns></returns>
        public static ReceiptModel Calculate(this RatesModel rates, ParkingTimeModel parkingTime)
        {
            if (parkingTime.Entry > parkingTime.Exit)
            {
                throw new Exception("Exit time cannot be before entry time!");
            }
            // TODO any other validation here

            return
                // first check for a matching flat rate
                (rates.FlatRates.Calculate(parkingTime)
                 // ok, now do we match a standard rate?
                 ?? rates.StandardRates.Calculate(parkingTime)
                 // no matches to any rates, fall back to the day rate
                 ?? DayRateCalculator.Calculate(rates.DefaultRatePerDay, parkingTime));
        }
Exemplo n.º 4
0
 public static double GetHoursParked(this ParkingTimeModel parkingTimes)
 {
     return((parkingTimes.Exit - parkingTimes.Entry).TotalHours);
 }
Exemplo n.º 5
0
 public static double GetCalendarDaysParked(this ParkingTimeModel parkingTimes)
 {
     return((parkingTimes.Exit.Date - parkingTimes.Entry.Date).TotalDays + 1);
 }
Exemplo n.º 6
0
 public static bool IsMatch(this StandardRatePriceModel rate, ParkingTimeModel parkingTimes)
 {
     return(parkingTimes.GetHoursParked() <= rate.UpToHours);
 }