コード例 #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));
        }