public decimal QualifyAmount(LoanQualificationApplication app) { decimal amount = app.NetIncome * settings.NetIncomeThresold; List <Loan> loans = unitOfWork.Loans.GetAllLoansAsBorrower(app.ApplicationUserId); int loanCount = loans.Count; amount = loanCount == 0 ? amount > settings.MaxiumAmountOnFirstLoan ? settings.MaxiumAmountOnFirstLoan : amount : amount; return(amount); }
public QualificationResult Qualify(string userId) { QualificationResult result = new QualificationResult(); QualificationSettings settings = new QualificationSettings(); LoanQualificationApplication app = unitOfWork.LoanApplications.GetLatestApp(userId); if (app.NetIncome < settings.MinimumNetIncome) { result.QualifyAmount = 0; result.DeniedReason = "Net income doesn't meet required minimum"; return(result); } result.QualifyAmount = QualifyAmount(app); if (DateTime.Now > (app.CreatedDate.AddDays(settings.AppValidDays))) { result.DeniedReason = "Qualification out of date"; return(result); } List <Loan> loansInNegStatus = unitOfWork.Loans.GetLoansInNegativeStatus(userId); if (loansInNegStatus.Count > 0) { result.DeniedReason = "laon(s) in negative status"; return(result); } BankAccount activeBankAccount = unitOfWork.BankAccounts.GetActive(userId); if (activeBankAccount == null) { result.DeniedReason = "No Active Bank account"; return(result); } Transaction lastTransaction = unitOfWork.Transactions.GetLastTransaction(activeBankAccount.Id); if (lastTransaction != null && lastTransaction.StatusId == (int)TransactionStatuses.Bounced || lastTransaction.StatusId == (int)TransactionStatuses.Failed) { result.DeniedReason = "Last Transaction Failed"; return(result); } if (activeBankAccount.IsAuthorized) { result.DeniedReason = "Bank Account Not Authorized"; return(result); } if (activeBankAccount.IsVerified) { result.DeniedReason = "Bank Account Not Verified"; return(result); } return(result); }