public PenaltyOutputModel Process(PenaltyInputModel inputViewModel)
        {
            if (inputViewModel == null)
            {
                throw new Exception($"{typeof(PenaltyInputModel).FullName} can not be null!");
            }
            try
            {
                var _countryEnum = (CountryEnum)System.Enum.Parse(typeof(CountryEnum), inputViewModel.Country.Currency);

                var _penaltyCalculationService = _factoryPatternResolver.Resolve(_countryEnum);

                var businessDays = _penaltyCalculationService.GetBusinessDays(inputViewModel);

                var result = _penaltyCalculationService.Calculate(businessDays, inputViewModel.Country.Currency);

                return(new PenaltyOutputModel {
                    BusinessDays = businessDays, TotalPrice = result.TotalPrice, CurrencySymbol = result.Currency
                });
            }
            catch
            {
            }
            return(new PenaltyOutputModel());
        }
Beispiel #2
0
        public int GetBusinessDays(PenaltyInputModel inputModel)
        {
            int TotalBusinessDays = 0;

            var holidays = inputModel.Country.Holidays.Select(s => s.Date);

            var dayDifference = (int)inputModel.To.Subtract(inputModel.From).TotalDays;

            for (var date = inputModel.From; date <= inputModel.To; date = date.AddDays(1))
            {
                if (date.DayOfWeek != DayOfWeek.Saturday &&
                    date.DayOfWeek != DayOfWeek.Sunday &&
                    !holidays.Contains(date))
                {
                    TotalBusinessDays++;
                }
            }

            return(TotalBusinessDays);
        }
        public IActionResult Index(PenaltyInputModel model)
        {
            setDropDownListForCountry();

            if (ModelState.IsValid)
            {
                var _country = _countryRepository.GetCountryById(model.Country.CountryId);
                model.Country = _country;

                var item = _penaltyCalculationProcessor.Process(model);

                if (item != null)
                {
                    ViewBag.BusinessDays   = item.BusinessDays;
                    ViewBag.Penalty        = item.TotalPrice;
                    ViewBag.CurrencySymbol = item.CurrencySymbol;
                    ViewBag.ShowResult     = true;
                }
                return(View(model));
            }
            return(View(model));
        }