Exemplo n.º 1
0
 public void Test(double balance, double interestRate, int years, double expected)
 {
     {
         var sut    = new LoanInterest();
         var result = sut.CalLoan(balance, interestRate, years);
         // Assert.Equal(expected, result);
     }
 }
Exemplo n.º 2
0
 public void Delete(LoanInterest delObj)
 {
     using (var session = GetSession())
     {
         using (var trans = session.BeginTransaction())
         {
             session.Delete(delObj);
             trans.Commit();
         }
     }
 }
Exemplo n.º 3
0
 public void Save(LoanInterest saveObj)
 {
     using (var session = GetSession())
     {
         using (var trans = session.BeginTransaction())
         {
             session.FlushMode = FlushMode.Commit;
             session.SaveOrUpdate(saveObj);
             trans.Commit();
             session.Flush();
             //}
         }
     }
 }
Exemplo n.º 4
0
        public void CalculateLoan([FromBody] Loan loan)
        {
            var calculate = new LoanInterest();

            var keepBalance = calculate.CalLoan(loan.amount, loan.interestRate, loan.numOfYears);

            foreach (var item in keepBalance)
            {
                loans.Add(new Loan()
                {
                    interestRate = item.interestRate,
                    amount       = item.amount,
                    numOfYears   = item.numOfYears,
                    TotalPaid    = item.TotalPaid
                });
            }
        }
Exemplo n.º 5
0
        public List <LoanInterest> CalculateInterestPerYear(LoanInterest model)
        {
            var interest     = 0.0;
            var totalBalance = 0.0;
            var listBalance  = new List <double>();

            for (int i = 0; i < model.Year; i++)
            {
                interest           = (model.Balance * model.InterestRate) / 100;
                model.TotalBalance = model.Balance + model.Interest;
                loanInterest.Add(model);
            }

            var result = listBalance.ToArray();

            return(loanInterest);
        }
Exemplo n.º 6
0
        public void Post(LoanInterest model)
        {
            var year        = model.Year;
            var listBalance = new List <LoanInterest>();

            for (int i = 1; i <= year; i++)
            {
                model.Interest     = model.Balance * model.InterestRate / 100;
                model.TotalBalance = model.Balance + model.Interest;
                model.Year         = i;
                loanInterest.Add(new LoanInterest()
                {
                    InterestRate = model.InterestRate,
                    Balance      = model.Balance,
                    Year         = model.Year,
                    Interest     = model.Interest,
                    TotalBalance = model.TotalBalance,
                });
                model.Balance = model.TotalBalance;
            }
        }
Exemplo n.º 7
0
 private LoanInfo(LoanType ltype, int minimumdaily, int maximumdaily, int daysforpayback, LoanInterest interest)
 {
     LType          = ltype;
     MinimumDaily   = minimumdaily;
     MaximumDaily   = maximumdaily;
     DaysForPayBack = daysforpayback;
     Interest       = interest;
     if (Interest == null)
     {
         if (ltype == LoanType.Small)
         {
             Interest = new DailyInterest(0.01);
         }
         else if (ltype == LoanType.Medium)
         {
             Interest = new DailyInterest(0.015);
         }
         else
         {
             Interest = new DailyInterest(0.02);
         }
     }
 }
Exemplo n.º 8
0
        public ActionResult Create(Loan loan, HttpPostedFileBase fileAgreement, HttpPostedFileBase fileIrrevocable, HttpPostedFileBase fileGuarantors)
        {
            if (ModelState.IsValid)
            {
                #region  Validate File Type

                string fileAgreementName, fileIrrevocableName, fileGuarantorsName, extension;
                if (fileAgreement != null && fileAgreement.ContentLength > 0)
                {
                    extension = Path.GetExtension(fileAgreement.FileName);
                    if (extension != ".jpg" && extension != ".jpeg" && extension != ".png")
                    {
                        ModelState.AddModelError("Invalid Image", "Please upload .jpg or .png image.");
                        return(View(loan));
                    }
                    fileAgreementName    = Guid.NewGuid() + extension;
                    loan.ImgAgreementUrl = ConfigurationManager.AppSettings["Azure:StorageUrl"] + BlobContainer.loan.ToString() + "/" + fileAgreementName;
                }
                else
                {
                    ModelState.AddModelError("Invalid Image", "Please upload image for signed agreement form.");
                    return(View(loan));
                }

                if (fileIrrevocable != null && fileIrrevocable.ContentLength > 0)
                {
                    extension = Path.GetExtension(fileIrrevocable.FileName);
                    if (extension != ".jpg" && extension != ".jpeg" && extension != ".png")
                    {
                        ModelState.AddModelError("Invalid Image", "Please upload .jpg or .png image.");
                        return(View(loan));
                    }

                    fileIrrevocableName    = Guid.NewGuid() + extension;
                    loan.ImgIrrevocableUrl = ConfigurationManager.AppSettings["Azure:StorageUrl"] + BlobContainer.loan.ToString() + "/" + fileIrrevocableName;
                }
                else
                {
                    ModelState.AddModelError("Invalid Image", "Please upload image for signed irrevocable authority form.");
                    return(View(loan));
                }

                if (fileGuarantors != null && fileGuarantors.ContentLength > 0)
                {
                    extension = Path.GetExtension(fileGuarantors.FileName);
                    if (extension != ".jpg" && extension != ".jpeg" && extension != ".png")
                    {
                        ModelState.AddModelError("Invalid Image", "Please upload .jpg or .png image.");
                        return(View(loan));
                    }

                    fileGuarantorsName    = Guid.NewGuid() + extension;
                    loan.ImgGuarantorsUrl = ConfigurationManager.AppSettings["Azure:StorageUrl"] + BlobContainer.loan.ToString() + "/" + fileGuarantorsName;
                }
                else
                {
                    ModelState.AddModelError("Invalid Image", "Please upload image for signed irrevocable authority form.");
                    return(View(loan));
                }

                #endregion

                if (!_context.Customers.Any(x => x.AccountNo == loan.AccountNo))
                {
                    ModelState.AddModelError("Account Not Exists", "Account does not exists.");
                    return(View(loan));
                }

                var deposit = _context.CustomerSavings.Where(x => x.AccountNo == loan.AccountNo).Sum(x => x.Credit - x.Debit);
                var percent = loan.amount * Convert.ToDecimal(0.10);

                if (deposit <= percent)
                {
                    ModelState.AddModelError("No 10% Deposit", "This customer has no 10% deposit in his/her account.");
                    return(View(loan));
                }

                loan.LoanStatus = "active"; //set loan status to active

                loan.Customername =
                    (from s in _context.Customers
                     where s.AccountNo == loan.AccountNo
                     select s.Name).FirstOrDefault();
                if (loan.Customername == null || loan.Customername == "")
                {
                    //return customer not registered errorr:09256A
                    return(Redirect("~/Error/ErrorCode?ErrorCode=09256A"));
                }
                //if we get here customer has been enrolled
                loan.createdby = User.Identity.Name.ToString();
                //loan.DateCreated = DateTime.Now.ToShortDateString();
                loan.DateCreated = DateTime.Now;

                //DateTime completionDate = DateTime.Parse(loan.DateOfCommencement).AddMonths(Int32.Parse(loan.Duration));
                DateTime completionDate = loan.DateOfCommencement.AddMonths(Int32.Parse(loan.Duration));

                //loan.DateOfTermination = completionDate.ToShortDateString();
                loan.DateOfTermination = completionDate;

                //save amount borrowed
                var amountBorred = new Borrowed
                {
                    DateCreated    = DateTime.Now.ToShortDateString(),
                    accountNo      = loan.AccountNo,
                    amountborrowed = loan.amount
                };

                //create a loan transaction record
                var loanTransaction = new LoanTransaction
                {
                    DateCreated = DateTime.Now.ToShortDateString(),
                    AccountNo   = loan.AccountNo,
                    amount      = loan.amount,
                    refund      = decimal.Parse("0"),//credit
                    createdby   = User.Identity.Name.ToString()
                };

                //customer must pay 10% of loan upfront. create loan interest record.
                var loanInterest = new LoanInterest
                {
                    accountNo     = loan.AccountNo,
                    intrestAmount = Decimal.Parse("0.1") * loan.amount,
                };
                _context.LoanInterests.Add(loanInterest);
                _context.Borrows.Add(amountBorred);
                _context.Loans.Add(loan);
                _context.LoanTransactions.Add(loanTransaction);
                _context.SaveChanges();

                #region Save Images

                if (fileAgreement != null && fileAgreement.ContentLength > 0)
                {
                    FileHelper.UploadImage(fileAgreement.InputStream, fileAgreementName, BlobContainer.loan);
                }

                if (fileIrrevocable != null && fileIrrevocable.ContentLength > 0)
                {
                    FileHelper.UploadImage(fileIrrevocable.InputStream, fileIrrevocableName, BlobContainer.loan);
                }

                if (fileGuarantors != null && fileGuarantors.ContentLength > 0)
                {
                    FileHelper.UploadImage(fileGuarantors.InputStream, fileGuarantorsName, BlobContainer.loan);
                }

                #endregion

                return(RedirectToAction("Index"));
            }

            return(View(loan));
        }
Exemplo n.º 9
0
 public LoanInfo WithInterest(LoanInterest interest)
 {
     Interest = interest;
     return(this);
 }