public PaymentPlanResponse Analyze(PaymentPlanRequest plan) { Validate(plan); var initialFee = plan.Apartment.Price * MINIMUM_LEGAL_INITIAL_FEE; var totalPlanAmmount = CalculateTotalFee(plan.Fees); if (totalPlanAmmount < initialFee) { throw new Exception("The plan doesn't sum at least the initial fee."); } var totalFeeCurrentYear = CaculateCurrentYearTotalFee(plan); if (totalFeeCurrentYear < initialFee * MINIMUM_PERCENTAGE_CURRENT_YEAR) { return new PaymentPlanResponse { IsApprovedByManager = false } } ; return(new PaymentPlanResponse { IsApprovedByManager = true }); }
private void Validate(PaymentPlanRequest plan) { if (plan.Apartment == null) { throw new Exception("No apartment was found"); } if (plan.Fees == null) { throw new Exception("No payment plan was found"); } }
private decimal CaculateCurrentYearTotalFee(PaymentPlanRequest plan) { var feesCurrentYear = plan.Fees.FindAll(f => f.CutoffDate.Year == DateTime.Now.Year); return(CalculateTotalFee(feesCurrentYear)); }
public IHttpActionResult Analyze([FromBody] PaymentPlanRequest plan, CancellationToken cancellationToken = default(CancellationToken)) { var response = _paymentPlanManager.Analyze(plan); return(Ok(response)); }