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, }); }
public static ReceiptModel GetRates(DateTime entry, DateTime exit) { var rates = ParkingRatesProvider.GetRates(); var times = new ParkingTimeModel() { Entry = entry, Exit = exit, }; return(rates.Calculate(times)); }
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, }); }