Example #1
0
        public async Task <ParkingRateDto> Calculate(TimerDto input)
        {
            var specialRates = await _specialService.GetAllAsync();

            var normalRates = await _normalService.GetAllAsync();

            var result = new ParkingRateDto();

            // TODO: Refactor this with Abstraction like IValidator
            // TODO: and orchestrate with Chain of Responsibility pattern
            var resultSpecial = _specialService.Calculate(specialRates, input.Entry, input.Exit);

            result = resultSpecial;

            var resultNormal = _normalService.Calculate(normalRates, input.Entry, input.Exit);

            // choose for either normal vs special
            if (resultNormal.Price > 0 && (result.Price == 0 || result.Price > resultNormal.Price))
            {
                result.Name  = resultNormal.Name;
                result.Price = resultNormal.Price;
            }

            return(result);
        }
        public async Task <ParkingRateDto> Calculate(TimerDto input)
        {
            var specialRates = await _specialService.GetAllAsync();

            var standardRates = await _standardService.GetAllAsync();

            var result = new ParkingRateDto();

            var resultSpecial = _specialService.Calculate(specialRates, input.Entry, input.Exit);

            result = resultSpecial;

            var resultStandard = _standardService.Calculate(standardRates, input.Entry, input.Exit);

            // select the lowest price
            if (resultStandard.Price > 0 && (result.Price == 0 || result.Price > resultStandard.Price))
            {
                result.Name  = resultStandard.Name;
                result.Price = resultStandard.Price;
            }

            return(result);
        }