예제 #1
0
        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
            });
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
        private decimal CaculateCurrentYearTotalFee(PaymentPlanRequest plan)
        {
            var feesCurrentYear = plan.Fees.FindAll(f => f.CutoffDate.Year == DateTime.Now.Year);

            return(CalculateTotalFee(feesCurrentYear));
        }
예제 #4
0
        public IHttpActionResult Analyze([FromBody] PaymentPlanRequest plan, CancellationToken cancellationToken = default(CancellationToken))
        {
            var response = _paymentPlanManager.Analyze(plan);

            return(Ok(response));
        }