Exemple #1
0
        public LoanApplicationResult ProcessLoan(LoanApplication application)
        {
            // Check loan qualification rules
            List <ILoanQualificationRule> failingRules = _loanApprovalRules.Where
                                                             (rule => rule.CheckLoanApprovalRule(application) == false).ToList();

            if (failingRules.Count > 0)
            {
                LoanApplicationResult result = LoanApplicationResult.CreateDeniedResult(application, failingRules);
                return(result);
            }

            // Determine interest rate
            double   interestRate;
            double   creditScore = application.CreditScore;
            LoanRate rate        = _loanRates.FirstOrDefault(r =>
                                                             creditScore >= r.LowerCreditScore &&
                                                             creditScore <= r.UpperCreditScore);

            interestRate = rate.InterestRate;

            if (application.ApplicantType.ToLower() == "premiere")
            {
                interestRate = rate.InterestRate - .01;
            }

            // Determine monthly payment
            double monthlyPayment = CalculateLoanPayment(loanAmount: application.LoanAmount,
                                                         termYears: application.Term.Years, interestRate: interestRate);

            return(LoanApplicationResult.CreateApprovedResult(application, interestRate, monthlyPayment));
        }
Exemple #2
0
        /// <summary>
        ///     Requests a loan to a foreign country.
        /// </summary>
        /// <param name="country">The country to whom the request is performed.</param>
        private void AskForLoan(LenderCountry country)
        {
            userInterface.DisplayLoanApplicationScreen();

            LoanApplicationResult loanApplicationResult = engine.AskForLoan(country);

            userInterface.DisplayLoanApplicationResultScreen(loanApplicationResult);
        }
Exemple #3
0
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Result = _resultRepository.GetLoan(id.Value);

            if (Result == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #4
0
        public async Task <bool> EnqueueLoanApplicationResult(LoanApplicationResult result)
        {
            try
            {
                var json = JsonSerializer.Serialize <LoanApplicationResult>(result);
                await AzureQueue.AddMessageAsync(new CloudQueueMessage(json, false));

                Logger.LogInformation("Loan result enqueued");
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Error during loan result enqueue.");
                return(false);
            }
        }
        public LoanApplicationResult ProcessLoan(LoanApplication application)
        {
            // Check for loan qualification
            var failingRule = _loanApprovalRules.FirstOrDefault(rule => rule.CheckLoanApprovalRule(application) == false);

            if (failingRule != null)
            {
                var result = LoanApplicationResult.CreateDeniedResult(application, failingRule.RuleName);
                return(result);
            }

            // Applicant qualifies for the loan, so figure out the interest rate we can offer and the monthly payment
            double interestRate   = DetermineInterestRate(application);
            double monthlyPayment = CalculateLoanPayment(application.LoanAmount, application.Term.Years, interestRate);

            return(LoanApplicationResult.CreateApprovedResult(application, interestRate, monthlyPayment));
        }
Exemple #6
0
        /// <summary>
        ///     Asks for foreign aid in the form of a loan to either America or Russia.
        /// </summary>
        /// <param name="country">The country to which the loan request will be made.</param>
        /// <returns>The loan application result that includes if the loan has been approved or refused.</returns>
        public LoanApplicationResult AskForLoan(LenderCountry country)
        {
            LoanApplicationResult loanApplicationResult = new LoanApplicationResult
            {
                Country = country
            };

            if (IsTooEarlyForLoan())
            {
                loanApplicationResult.IsAccepted  = false;
                loanApplicationResult.RefusalType = LoanApplicationRefusalType.TooEarly;

                return(loanApplicationResult);
            }

            if (HasLoanBeenGrantedPreviously(country))
            {
                loanApplicationResult.IsAccepted  = false;
                loanApplicationResult.RefusalType = LoanApplicationRefusalType.AlreadyUsed;

                return(loanApplicationResult);
            }

            GroupType groupType = groupService.GetGroupTypeByCountry(country);
            Group     group     = groupService.GetGroupByType(groupType);

            loanApplicationResult.GroupName = group.Name;

            if (group.Popularity <= governmentService.GetMonthlyMinimalPopularityAndStrength())
            {
                loanApplicationResult.IsAccepted  = false;
                loanApplicationResult.RefusalType = LoanApplicationRefusalType.NotPopularEnough;
            }
            else
            {
                loanApplicationResult.IsAccepted  = true;
                loanApplicationResult.RefusalType = LoanApplicationRefusalType.None;
                loanApplicationResult.Amount      = CalculateLoanAmount(group);
                accountService.ChangeTreasuryBalance(loanApplicationResult.Amount);
            }

            return(loanApplicationResult);
        }
Exemple #7
0
        public async Task <bool> SaveLoan(LoanApplicationResult loanApplication)
        {
            try
            {
                var record = new LoanApplicationResultRecord
                {
                    LoanApplication = loanApplication,
                    Id = Guid.NewGuid().ToString()
                };

                await InboxContainer.CreateItemAsync <LoanApplicationResultRecord>(record);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, $"Error saving loan application");
                return(false);
            }
        }
        /// <summary>
        ///     Displays the screen.
        /// </summary>
        /// <param name="loanApplicationResult">The load application result to be displayed on screen.</param>
        public void Show(LoanApplicationResult loanApplicationResult)
        {
            if (loanApplicationResult.IsAccepted)
            {
                ConsoleEx.WriteAt(1, 12, $"{loanApplicationResult.GroupName} will let you have");
                ConsoleEx.WriteAt(8, 14, $"{loanApplicationResult.Amount},000 DOLLARS");
            }
            else
            {
                if (loanApplicationResult.Country == LenderCountry.America)
                {
                    ConsoleEx.WriteAt(1, 12, "            \"nuts !\"            ");
                }
                else if (loanApplicationResult.Country == LenderCountry.Russia)
                {
                    ConsoleEx.WriteAt(1, 12, "             NIET !             ");
                }
            }

            pressAnyKeyControl.Show();
        }
 public void SaveLoanApplicationResult(LoanApplicationResult loanApplicationResult)
 {
     throw new NotImplementedException();
 }
        public static async Task <LoanApplicationResult> Orchestrate(
            [OrchestrationTrigger] IDurableOrchestrationContext context,
            [SignalR(HubName = "dashboard")] IAsyncCollector <SignalRMessage> dashboardMessages,
            ILogger logger)
        {
            var loanApplication = context.GetInput <LoanApplication>();
            var agencyTasks     = new List <Task <CreditAgencyResult> >();
            var agencies        = new List <CreditAgencyRequest>();
            var results         = new CreditAgencyResult[] { };

            logger.LogWarning($"Status of application for {loanApplication.Applicant.ToString()} for {loanApplication.LoanAmount}: Checking with agencies.");

            // start the process and perform initial validation
            bool loanStarted = await context.CallActivityAsync <bool>(nameof(Receive), loanApplication);

            // fan out and check the credit agencies
            if (loanStarted)
            {
                agencies.AddRange(new CreditAgencyRequest[] {
                    new CreditAgencyRequest {
                        AgencyName = "Contoso, Ltd.", AgencyId = "contoso", Application = loanApplication
                    },
                    new CreditAgencyRequest {
                        AgencyName = "Fabrikam, Inc.", AgencyId = "fabrikam", Application = loanApplication
                    },
                    new CreditAgencyRequest {
                        AgencyName = "Woodgrove Bank", AgencyId = "woodgrove", Application = loanApplication
                    },
                });

                foreach (var agency in agencies)
                {
                    agencyTasks.Add(context.CallActivityAsync <CreditAgencyResult>(nameof(CheckCreditAgency), agency));
                }

                await dashboardMessages.AddAsync(new SignalRMessage
                {
                    Target    = "agencyCheckPhaseStarted",
                    Arguments = new object[] { }
                });

                // wait for all the agencies to return their results
                results = await Task.WhenAll(agencyTasks);

                await dashboardMessages.AddAsync(new SignalRMessage
                {
                    Target    = "agencyCheckPhaseCompleted",
                    Arguments = new object[] { !(results.Any(x => x.IsApproved == false)) }
                });
            }

            var response = new LoanApplicationResult
            {
                Application = loanApplication,
                IsApproved  = loanStarted && !(results.Any(x => x.IsApproved == false))
            };

            logger.LogWarning($"Agency checks result with {response.IsApproved} for loan amount of {response.Application.LoanAmount} to customer {response.Application.Applicant.ToString()}");

            await dashboardMessages.AddAsync(new SignalRMessage
            {
                Target    = "loanApplicationComplete",
                Arguments = new object[] { response }
            });

            return(response);
        }
 public void SaveLoanApplicationResult(LoanApplicationResult loanApplicationResult)
 {
     _context.LoanApplicationResults.Add(loanApplicationResult);
     _context.SaveChanges();
 }
Exemple #12
0
 public void DisplayLoanApplicationResultScreen(LoanApplicationResult loanApplicationResult) => loanApplicationResultScreen.Show(loanApplicationResult);
Exemple #13
0
        public async Task <ActionResult> Post([FromBody] LoanApplicationResult loanApplicationResult)
        {
            await InboxQueue.EnqueueLoanApplicationResult(loanApplicationResult);

            return(Accepted());
        }