private LeasingCalcResultsVM GetResultsForModel(LeasingCalcResults res) { LeasingCalcResultsVM mRes = new LeasingCalcResultsVM(); mRes.AnnualPercentRate = res.AnnualPercentRate; mRes.TotalFees = res.TotalFees; mRes.TotalPaidWithFees = res.TotalPaidWithFees; return(mRes); }
public ActionResult LeasingCalculator(LeasingCalcParamsVM model) { if (!model.IsModelValid(ModelState)) { return(PartialView("_InvalidLeasingParamsPartial", model)); } var parameters = GetParamsFromModel(model); LeasingCalcResults leasingResult = this.calculatorService.CalculateLeasing(parameters); LeasingCalcResultsVM leasingViewModelResult = GetResultsForModel(leasingResult); return(PartialView("_LeasingResultsPartial", leasingViewModelResult)); }
public LeasingCalcResults Calculate(LeasingCalcParams p) { IsParamsValid(p); LeasingCalcResults res = new LeasingCalcResults(); decimal loanAmount = (decimal)p.Price - (decimal)p.InitialInstallment; APRCalculator aprCalc = new APRCalculator(loanAmount); decimal initialFee = GetFeeAmount(p.Price.Value, p.InitialManagementFee, p.TreatInitialManagementFeeAsPercent); aprCalc.AddInstalment(initialFee, 0); for (int i = 1; i <= p.Period; i++) { aprCalc.AddInstalment(p.MonthlyInstallment.Value, 365.25M / 12M * i); } res.AnnualPercentRate = Math.Round(aprCalc.Calculate(), 2); res.TotalFees = Math.Round(initialFee, 2); res.TotalPaidWithFees = Math.Round(p.MonthlyInstallment.Value * p.Period.Value + p.InitialInstallment.Value + res.TotalFees, 2); return(res); }