public async Task <IEnumerable <LoanRepaymentCashFlowItem> > GenerateCashFlow(LoanApplication loanApplication, int numberOfYears) { var externalLoans = await existingLoanRepository .GetExternalActiveLoan(loanApplication.Id); return(externalLoans.Select(x => { var annualAmortizations = new List <decimal>(); for (var i = 0; i < numberOfYears; i++) { DateTime startDate = loanApplication.RecastDate.AddYears(i); decimal annualAmortization = externalLoanAnnualAmortizationRepository.CalculateAnnualAmortization(x, startDate); if (DateTime.Compare(startDate, x.MaturityDate) > 0) { annualAmortization = 0; } annualAmortizations.Add( annualAmortization ); } return new LoanRepaymentCashFlowItem { Name = x.Name, AnnualRepayments = annualAmortizations }; })); }
public async Task <IEnumerable <LoanAnnualAmortization> > GetAnnualAmortizations(long loanApplicationId, DateTime startDate) { var existingLoans = await existingLoanRepository.GetExternalActiveLoan(loanApplicationId); return(existingLoans.Select(x => new LoanAnnualAmortization { Name = x.Name, EstimatedAmortization = CalculateAnnualAmortization(x, startDate) })); }