public async Task <AmendDirectDebitVm> Build(IApplicationSessionState session, Guid lowellReferenceSurrogateKey, string caseflowUserId)
        {
            string lowellReference = session.GetLowellReferenceFromSurrogate(lowellReferenceSurrogateKey);
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto {
                LowellReference = lowellReference
            };
            var currentDirectDebit = await _getCurrentDirectDebitProcess.GetCurrentDirectDebit(accountReferenceDto);

            IncomeAndExpenditureApiModel incomeAndExpenditureDto = await _apiGatewayProxy.GetIncomeAndExpenditure(lowellReference);

            var workingAccounts = 0;

            if (caseflowUserId != null)
            {
                List <AccountSummary> accounts = await _accountService.GetAccounts(caseflowUserId);

                workingAccounts = accounts.Count(a => !a.AccountStatusIsClosed);
            }

            PaymentOptionsDto paymentOptionsDto = await _apiGatewayProxy.GetPaymentOptions(accountReferenceDto);

            var obj = new AmendDirectDebitVm
            {
                LowellReference    = currentDirectDebit.LowellReference,
                ClientName         = currentDirectDebit.ClientName,
                OutstandingBalance = currentDirectDebit.OutstandingBalance,
                DirectDebitAmount  = null,
                PlanType           = currentDirectDebit.PlanType,
                EarliestStartDate  = currentDirectDebit.EarliestInstalmentDate,
                LatestStartDate    = currentDirectDebit.LatestPlanSetupDate,
                PlanStartDate      = currentDirectDebit.EarliestInstalmentDate,
                DiscountedBalance  = currentDirectDebit.DiscountedBalance,
                DiscountAmount     = currentDirectDebit.DiscountAmount,
                DiscountExpiry     = currentDirectDebit.DiscountExpiry,
                DiscountPercentage = currentDirectDebit.DiscountPercentage,
                DiscountedBalancePreviouslyAccepted = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                Frequency                    = _buildFrequencyListProcess.BuildFrequencyList(currentDirectDebit.DirectDebitFrequencies),
                IandENotAvailable            = incomeAndExpenditureDto == null,
                IandELessThanOrIs12MonthsOld = (incomeAndExpenditureDto != null && incomeAndExpenditureDto.Created.AddMonths(12).Date >= DateTime.Now.Date),
                AverageMonthlyPayment        = _portalSetting.AverageMonthlyPaymentAmount,
                MonthlyDisposableIncome      = (incomeAndExpenditureDto == null ? 0 :
                                                (incomeAndExpenditureDto.DisposableIncome * (_portalSetting.MonthlyDisposableIncomePlanSetupPercentage / 100)))
            };

            obj.AccountCount = workingAccounts;

            if (workingAccounts > 1)
            {
                obj.MonthlyDisposableIncomePerAccount =
                    obj.MonthlyDisposableIncome / workingAccounts;
            }
            else
            {
                obj.MonthlyDisposableIncomePerAccount = obj.MonthlyDisposableIncome;
            }

            return(obj);
        }
コード例 #2
0
        public void GetCurrentDirectDebit_RetrievesDtoViaProxy()
        {
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto();

            AmendDirectDebitPaymentDto amendDirectDebitPaymentDto = new AmendDirectDebitPaymentDto();

            _apiGatewayProxy.Setup(x => x.GetCurrentDirectDebit(accountReferenceDto)).ReturnsAsync(amendDirectDebitPaymentDto);

            Assert.AreEqual(amendDirectDebitPaymentDto, _getCurrentDirectDebitProcess.GetCurrentDirectDebit(accountReferenceDto).Result);
        }