public ActionResult TakeLoan(Loans loan) { var findCustomer = _contextCustomerAccount.Get(loan.Id); var loanStatus = _loanLogic.HasUnpaidLoan(findCustomer.AccountNumber); //var culture = new CultureInfo("ig-ng"); loan.Amount = Convert.ToDecimal(Request.Form["LoanAmount"], CultureInfo.InvariantCulture); loan.Narration = Request.Form["Narration"]; loan.DurationInMonths = Convert.ToInt32(Request.Form["Duration"]); var custId = Request.Form["Id"]; var id = Request.Form["customerId"]; if (loanStatus) { TempData["Message"] = "Customer has an Unpaid loan"; return(RedirectToAction("TakeLoan")); } else { var customerAccount = _contextCustomerAccount.Get(Convert.ToInt32(custId)); loan.CustomerAccountId = customerAccount.Id; loan.Name = customerAccount.AccountName; loan.CustomerAccountNumber = customerAccount.AccountNumber; loan.AccountNumber = _logic.generateAccountNumber("Loan", id); var amount = loan.Amount; var duration = loan.DurationInMonths; var getAll = _loanContextLogic.GetAll(); if (getAll.Count() != 0) { var resultValue = getAll.Single(); loan.InterestRate = resultValue.DebitInterestRate; loan.LoanBalance = loan.Amount; loan.Id = 0; loan.StartDate = DateTime.Now; loan.Status = true; loan.DaysCount = 0; loan.EndDate = _loanLogic.CalcEndDate(loan.DurationInMonths); loan.Interest = Math.Round(_loanLogic.CalcInterestRate(amount, loan.InterestRate, duration), 4); loan.InterestRemaining = loan.Interest; loan.InterestDeduction = Math.Round(_loanLogic.CalcInterestDeduction(loan.Interest, loan.DurationInMonths), 4); loan.DailyLoanDeduction = Math.Round( _loanLogic.DailyLonDeductionAndPrincipalRemaining(loan.Amount, loan.DurationInMonths), 4); loan.PrincipalRemaining = Math.Round(loan.Amount / (loan.DurationInMonths * 30), 4); } _loanLogic.SaveLoan(loan); //Create customer loan account var customerLoanAcct = new CustomerAccount { customerId = customerAccount.customerId, AccountName = customerAccount.AccountName, AccountNumber = loan.AccountNumber, branchName = customerAccount.branchName, Balance = 0, AccountType = AccountType.Loan, isClosed = false }; _logic.SavePost(customerLoanAcct); var loanAccountId = _contextCustomerAccount.GetByAccountNumber(loan.AccountNumber); //Crediting customer Account with loan taken _loanLogic.CreditCustomerAccount(amount, loan.CustomerAccountId, customerAccount); _loanLogic.DebitCustomerAccount(amount, loanAccountId.Id, loanAccountId); ViewBag.Message = "Loan Application Successful"; ViewBag.Status = true; } //return View(); return(RedirectToAction("LoanIndex", "CustomerAccount")); }