コード例 #1
0
        public void AddLoan(int accountHolderId, double amount, string type)
        {
            Loan newLoan = new Loan
            {
                AccountHolderId = accountHolderId,
                Amount          = amount,
                Status          = 1,
                TypeOfLoan      = type,
                AmountLeft      = amount
            };

            try
            {
                List <Loan> allLoan = _loanRepository.FindAllLoansById(accountHolderId);

                if (allLoan.Count < 1)
                {
                    _loanRepository.CreateLoan(newLoan);
                }
                else
                {
                    Loan activeLoan = FindActiveLoan(allLoan);
                    if (activeLoan == null)
                    {
                        _loanRepository.CreateLoan(newLoan);
                        Console.WriteLine($"You Have Succesfully Being Grant A {type} Loan of {amount}");
                    }

                    else
                    {
                        throw new Exception($"You currently have an unpaid loan of {activeLoan.AmountLeft}. Please pay up to qualify for another");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
        public int CreateLoan(CreateLoanDto loan)
        {
            var loanId = _loanRepository.CreateLoan(new Loan
            {
                Amount      = loan.Amount,
                BorrowerId  = loan.BorrowerId,
                LenderId    = loan.LenderId,
                LoanDate    = loan.LoanDate,
                Description = loan.Description,
                Status      = Status.Loan.ToPay
            });

            if (loanId != 0)
            {
                _userService.ChangeUserBalance(loan.BorrowerId, loan.Amount * -1);
                _userService.ChangeUserBalance(loan.LenderId, loan.Amount);
            }

            return(loanId);
        }
コード例 #3
0
        //[Authorize(Policy = Claims.Cashier)]
        public async Task <IActionResult> RegisterLoan([FromForm] LoanModel model)
        {
            if (ModelState.IsValid)
            {
                string AccountNumber = Generate.GenerateAccountNumber();
                while (_custManager.GetAccountViaAccountNumber(AccountNumber) != null)
                {
                    AccountNumber = Generate.GenerateAccountNumber();
                }

                var user = new User
                {
                    Email    = model.EmailAdress,
                    UserName = model.EmailAdress,
                };
                var isExistEmail = _context.Users.SingleOrDefault(x => x.Email == model.EmailAdress);

                if (isExistEmail != null)
                {
                    throw new Exception("Email already taken");
                }

                // var result = await _userManager.CreateAsync(user, model.Password);

                var resultTrue = await _userManager.CreateAsync(user, model.Password);

                if (resultTrue.Succeeded)
                {
                    await _userManager.AddClaimAsync(user, new Claim(Claims.User, "true"));

                    dynamic code = Generate.GenerateVerificationCode();


                    string LoginUser = User.Identity.Name;
                    var    userId    = User.FindFirstValue(ClaimTypes.NameIdentifier);


                    String Passport  = "";
                    string Signature = "";
                    var    files     = HttpContext.Request.Form.Files;

                    if (files != null)
                    {
                        // var file = Image;
                        //There is an error here
                        var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads\\img\\");
                        var upload  = Path.Combine(_hostingEnvironment.WebRootPath, "upload\\img\\");
                        if (files.Count() > 0)
                        {
                            Passport  = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(files[0].FileName);
                            Signature = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(files[1].FileName);
                            //var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                            var fileStream  = new FileStream(Path.Combine(uploads, Passport), FileMode.Create);
                            var fileStream2 = new FileStream(Path.Combine(upload, Signature), FileMode.Create);

                            files[0].CopyTo(fileStream);
                            files[1].CopyTo(fileStream2);
                            // file.CopyTo(fileStream);
                            model.CustImageThumbnailUrl = Passport;
                            model.ScannThumbnailUrl     = Signature;
                        }
                        var result = await _loanRepo.CreateLoan(model, AccountNumber, LoginUser, userId);

                        if (result != null)
                        {
                            var subjectTo = "ALERT NOTIFICATION";

                            var messages = "</br><b> Dear </b>" + result.recepientName;
                            messages += ("<br />");
                            messages += "</br><b> Your account number: </b>" + AccountNumber;
                            messages += ("<br />");
                            messages += "</br><b>  Amount to collect: #</b>" + result.AmountGiven;
                            messages += ("<br />");
                            messages += "</br><b> Total amount to pay: #</b>" + result.Amount;
                            messages += ("<br />");
                            messages += "</br><b> Interest Rate: </b>" + result.Interest_Rate + "%";
                            messages += ("<br />");
                            messages += "</br><b> loan return: </b>" + result.Frequency;
                            messages += ("<br />");
                            messages += "</br><b> Loan due month: </b>" + result.Deadline;
                            messages += ("<br />");
                            messages += "</br><b> Date registered: </b>" + result.Date;
                            messages += ("<br />");
                            messages += ("<br />");
                            messages += "</br>Regards";

                            await _emailSender.SendEmailAsync(result.recipientEmail, subjectTo, messages, "");

                            //alert message
                            TempData["Message"] = "Account number " + " " + AccountNumber + " " + " Successfully created";

                            dynamic transRef = TempData["Message"];

                            Alert("success", transRef, NotificationType.success);

                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        TempData["Error"] = "bad";
                    }
                }
                //}
            }
            return(View(model));
        }