public async Task <IActionResult> Create(LoanCreateModel loanModel) { HttpResponseMessage response = await httpClient.PostAsJsonAsync(LoansAPIEndpoint, loanModel); Loan loan = await response.Content.ReadAsAsync <Loan>(); return(RedirectToAction(nameof(LoansController.Details), "Loans", new { id = loan.Id })); }
public async Task <ActionResult> Create(LoanCreateModel loanCreateModel) { if (loanCreateModel != null) { var result = await this._loanLoanService.CreateLoan(loanCreateModel, this.Username); return(Ok(result)); } return(null); }
public async Task <CreateLoanResponseModel> CreateLoanAsync(LoanCreateModel model) { await _loanCreateModelValidator.ValidateAndThrowAsync(model); var regularAccountCreateModel = _mapper.Map <CreateAccountTemplateModel>(model); regularAccountCreateModel.AccountActivity = AccountActivity.Active; regularAccountCreateModel.AccountType = AccountType.Regular; var(regularAccount, regularAccountPin) = await _accountService.GetAccountTemplateAsync(regularAccountCreateModel); var loanPaymentAccountCreateModel = _mapper.Map <CreateAccountTemplateModel>(model); loanPaymentAccountCreateModel.AccountActivity = AccountActivity.Active; loanPaymentAccountCreateModel.AccountType = AccountType.LoanPayment; var(loanPaymentAccount, loanPaymentAccountPin) = await _accountService.GetAccountTemplateAsync(loanPaymentAccountCreateModel); var loanContract = _context.Add(_mapper.Map <LoanContract>(model)).Entity; loanContract.LoanPaymentAccount = loanPaymentAccount; loanContract.RegularAccount = regularAccount; var bankDevelopmentFundAccount = await _accountService.GetBankDevelopmentFundAccountForCurrencyAsync(model.CurrencyId); var loanTransaction = new Transaction { ContractNumber = loanContract.ContractNumber, CurrencyId = loanContract.CurrencyId, Amount = loanContract.Amount, CreatedAt = loanContract.ProgramStartDate, SenderAccountNumber = bankDevelopmentFundAccount.AccountNumber, ReceiverAccountNumber = regularAccount.AccountNumber }; _context.Transactions.Add(loanTransaction); await _context.SaveChangesAsync(); return(new CreateLoanResponseModel { RegularAccountPin = regularAccountPin, LoanPaymentAccountPin = loanPaymentAccountPin }); }
public async Task <LoanCreateModel> CreateLoan(LoanCreateModel loanCreateModel, string username) { var loan = new Loan() { CustomerId = loanCreateModel.CustomerId, InitialLoanAmount = loanCreateModel.InitialLoanAmount, DateGranted = loanCreateModel.DateGranted, PeriodMonths = loanCreateModel.PeriodMonths, Interest = loanCreateModel.Interest, Security = loanCreateModel.Security, PropertyValue = loanCreateModel.PropertyValue != null ? loanCreateModel.PropertyValue.Value : 0, CapitalOutstanding = loanCreateModel.CapitalOutstanding, CreatedBy = username, CreatedOn = DateTime.Now }; // Add Loan Details.. decimal totalInterest = 0; for (int i = 1; i <= loanCreateModel.PeriodMonths; i++) { totalInterest += loanCreateModel.CapitalOutstanding * loanCreateModel.Interest / 100; var loanDetail = new LoanDetail() { Loan = loan, Installment = i, Month = loanCreateModel.DateGranted.AddMonths(i), MonthlyInterest = loanCreateModel.CapitalOutstanding * loanCreateModel.Interest / 100, Balance = loanCreateModel.CapitalOutstanding + totalInterest, InterestType = InterestType.SimpleInterest, CreatedBy = username, CreatedOn = DateTime.Now }; loan.LoanDetails.Add(loanDetail); } var response = await this._loanRepository.AddAsyn(loan); loanCreateModel.Id = response.Id; return(loanCreateModel); }
public async Task <ActionResult <Guid> > CreateLoanAsync(LoanCreateModel model) { var createLoanResponseModel = await _loanService.CreateLoanAsync(model); return(Ok(createLoanResponseModel)); }