コード例 #1
0
 public CalculationServiceCalculator(
     Calculator calculator,
     IConfigurationService configurationService,
     OfferPriceCalculation offerPriceCalculation)
 {
     _calculator            = calculator ?? throw new ArgumentNullException(nameof(calculator));
     _configurationService  = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
     _offerPriceCalculation = offerPriceCalculation ?? throw new ArgumentNullException(nameof(offerPriceCalculation));
 }
コード例 #2
0
        /*public static List<PricedScheduledPeriod> ScheduleAndPricePeriods(ResolveSchedulingPeriodsRequest request,
         *  ArrangementRequest arrangementRequest, PriceCalculationParameters priceParams, OfferPriceCalculation priceCalc,
         *  string conversionMethod)
         * {
         *  var scheduledAndPricedPeriods = new List<PricedScheduledPeriod>();
         *  ArrangementRequest arrangementRequestTemp;
         *  foreach (var period in priceParams.ScheduledPeriods)
         *  {
         *      arrangementRequestTemp = Mapper.Map<ArrangementRequest, ArrangementRequest>(arrangementRequest);
         *      arrangementRequestTemp.CalculateOffer(priceParams, priceCalc, conversionMethod);
         *      scheduledAndPricedPeriods.Add(new PricedScheduledPeriod
         *      {
         *          Percentage = (double)(arrangementRequestTemp?.Conditions?.InterestRates?.Where(r => r.Kind == InterestRateKinds.RegularInterest).Select(r => r.CalculatedRate).FirstOrDefault() ?? 0),
         *          PeriodType = period.PeriodType,
         *          StartDate = period.StartDate,
         *          EndDate = period.EndDate,
         *          // TODO To be resolved from DMN maybe?
         *          UnitOfTime = CalculationService.Services.SimpleUnitOfTime.Y
         *      });
         *  }
         *  return scheduledAndPricedPeriods;
         * }*/

        public static List <PricedScheduledPeriod> PricePeriods(
            ArrangementRequest arrangementRequest, PriceCalculationParameters priceParams,
            OfferPriceCalculation priceCalc)
        {
            var scheduledAndPricedPeriods = new List <PricedScheduledPeriod>();
            var scheduledPeriods          = new List <ScheduledPeriod>();
            var rates = new List <InterestRateCondition>();

            if (priceParams.ScheduledPeriods != null)
            {
                priceParams.ScheduledPeriods.ForEach(p => scheduledPeriods.Add(p));
            }
            if (priceParams.InterestRates != null)
            {
                priceParams.InterestRates.ForEach(r => rates.Add(r));
            }
            foreach (var period in scheduledPeriods)
            {
                priceParams.ScheduledPeriods.Clear();
                priceParams.ScheduledPeriods.Add(period);
                _ = priceCalc.CalculatePrice(arrangementRequest, priceParams).Result;
                // arrangementRequest.CalculateOffer(priceParams, priceCalc, conversionMethod);
                scheduledAndPricedPeriods.Add(new PricedScheduledPeriod
                {
                    Percentage = (double)(arrangementRequest?.Conditions?.InterestRates?.Where(r => r.Kind == InterestRateKinds.RegularInterest).Select(r => r.CalculatedRate).FirstOrDefault() ?? 0),
                    PeriodType = period.PeriodType,
                    StartDate  = period.StartDate,
                    EndDate    = period.EndDate,
                    // TODO To be resolved from DMN maybe?
                    UnitOfTime = CalculationService.Services.SimpleUnitOfTime.Y
                });
            }
            if (scheduledPeriods != null)
            {
                priceParams.ScheduledPeriods = scheduledPeriods;
            }
            if (rates != null)
            {
                priceParams.InterestRates = rates;
            }
            return(scheduledAndPricedPeriods);
        }