示例#1
0
        private static bool IsWeekendRateApplicable(IEntryRequest request)
        {
            if (GetDaysDifference(request.EntryTimeLocal, request.ExitTimeLocal) > 2)
            {
                return(false);
            }

            return(Constants.WeekendDays.Contains(request.EntryTimeLocal.DayOfWeek.ToString()) && Constants.WeekendDays.Contains(request.ExitTimeLocal.DayOfWeek.ToString()));
        }
示例#2
0
        public static EntryResponse FromStandardRate(IStandardRate rate, IEntryRequest request)
        {
            if (rate == null)
            {
                return(null);
            }

            return(new EntryResponse()
            {
                RateName = rate.Name,
                RateType = rate.Type,
                Amount = rate.TotalPrice,
                RegistrationNo = request.RegistrationNo,
                EntryTime = request.EntryTime,
                ExitTime = request.ExitTime
            });
        }
示例#3
0
        private static IEntryResponse CalculateWeekdayParkingFee(IEntryRequest request)
        {
            var daysDifference = GetDaysDifference(request.EntryTimeLocal, request.ExitTimeLocal);

            if (daysDifference < 2)
            {
                var specialRates = JsonConvert.DeserializeObject <List <SpecialRate> >(Resources.specialrates).Where(r => !r.Weekend);

                var applicableSpecialRate = specialRates.SingleOrDefault(r => request.EntryTimeLocal.TimeOfDay >= TimeSpan.Parse(r.EntryPeriodStart) &&
                                                                         request.EntryTimeLocal.TimeOfDay <= TimeSpan.Parse(r.EntryPeriodEnd) &&
                                                                         request.ExitTimeLocal.TimeOfDay >= TimeSpan.Parse(r.ExitPeriodStart) &&
                                                                         request.ExitTimeLocal.TimeOfDay <= TimeSpan.Parse(r.ExitPeriodEnd));

                if (applicableSpecialRate != null)
                {
                    return(EntryResponse.FromSpecialRate(applicableSpecialRate, request));
                }
            }

            // Standard Rates
            StandardRate applicableStandardRate;
            var          standardRates = JsonConvert.DeserializeObject <List <StandardRate> >(Resources.standardrates);

            if (daysDifference == 0)
            {
                applicableStandardRate = standardRates.SingleOrDefault(r => request.ExitTimeLocal.TimeOfDay.Subtract(request.EntryTimeLocal.TimeOfDay).TotalMinutes > r.MinimumHours * 60 &&
                                                                       request.ExitTimeLocal.TimeOfDay.Subtract(request.EntryTimeLocal.TimeOfDay).TotalMinutes <= r.MaximumHours * 60);
            }
            else
            {
                applicableStandardRate            = standardRates.OrderByDescending(r => r.MaximumHours).FirstOrDefault();
                applicableStandardRate.TotalPrice = applicableStandardRate.TotalPrice * daysDifference;
            }


            return(EntryResponse.FromStandardRate(applicableStandardRate, request));
        }
示例#4
0
        private static IEntryResponse CalculateWeekendParkingFee(IEntryRequest request)
        {
            var weekendRate = JsonConvert.DeserializeObject <List <SpecialRate> >(Resources.specialrates).Single(r => r.Weekend);

            return(EntryResponse.FromSpecialRate(weekendRate, request));
        }
示例#5
0
 public static IEntryResponse CalculateParkingFee(IEntryRequest request)
 {
     return(IsWeekendRateApplicable(request) ? CalculateWeekendParkingFee(request) : CalculateWeekdayParkingFee(request));
 }