//Calculate the Hourly Rates between given range public async Task <ParkingRates> Calculate(DateTime Start, DateTime End) { ParkingRates objParkingRates = new ParkingRates(); //The fraction of next hour converted to full hour e.g. 1.3 hours mean 2 hours double hoursStayed = Math.Ceiling((double)(End - Start).TotalMinutes / 60); //Get the Hourly Rates List var serviceHourlyRatesList = await _parkingRatesRepository.GetAllHourlyRates(); //Compare the given duration in FlatRates List var parkingRatesDomainObject = serviceHourlyRatesList.AsEnumerable().Where (item => (hoursStayed > item.Hours.MinHours) && (hoursStayed <= item.Hours.MaxHours)). Select(item => item); //If duration falls into hourly rate range if (parkingRatesDomainObject.Any()) { objParkingRates = parkingRatesDomainObject.FirstOrDefault(); //Pick the Rate Name objParkingRates.Name = Enum.GetName(typeof(RateCategory), objParkingRates.Category); //If the stay is more than 24 hours then multiply rest of the days with daily rate, if (hoursStayed > 24) { objParkingRates.Price = Math.Ceiling((double)hoursStayed / 24) * objParkingRates.Price; } } return(objParkingRates); }
//Calculate the FlatRates between given range public async Task <ParkingRates> Calculate(DateTime Start, DateTime End) { ParkingRates objParkingRates = new ParkingRates(); var serviceFlatRatesList = await _parkingRatesRepository.GetAllFlatRates(); //Compare the given duration in FlatRates List - The expression is checking the selected Entry and Exit duration //Range in the FlatRates List, it matches the day of the week and time var parkingRatesDomainObject = serviceFlatRatesList.AsEnumerable().Where (item => CheckFlatRateDuration(item.Entry, Start.TimeOfDay) == true && CheckFlatRateDuration(item.Exit, End.TimeOfDay) == true && item.Days.Contains(Start.DayOfWeek) && item.Days.Contains(End.DayOfWeek)). Select(item => item); //If the duration falls into FlatRates if (parkingRatesDomainObject.Any()) { objParkingRates = parkingRatesDomainObject.FirstOrDefault(); //Pick the Name of FlatRates category objParkingRates.Name = Enum.GetName(typeof(RateCategory), objParkingRates.Category); } return(objParkingRates); }