Esempio n. 1
0
        public IActionResult HandleRegisterLender(LenderRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <Lender> Hasher = new PasswordHasher <Lender>();
                Lender NewLender = new Lender
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email,
                    CreatedAt = DateTime.Now,
                    UpdatedAt = DateTime.Now,
                    Money     = model.Money
                };
                NewLender.Password = Hasher.HashPassword(NewLender, model.Password);

                _context.Add(NewLender);
                _context.SaveChanges();
                Lender justEnteredLender = _context.lenders.SingleOrDefault(lender => lender.Email == model.Email);
                HttpContext.Session.SetString("UserName", justEnteredLender.FirstName);
                HttpContext.Session.SetInt32("UserId", justEnteredLender.LenderId);

                // return RedirectToAction("Success");
                return(RedirectToAction("GetLender", "Loan", new { LenderId = justEnteredLender.LenderId }));
            }
            System.Console.WriteLine("Not Valid!");
            ViewBag.Errors = new List <string>();
            return(View("RegisterLender"));
        }
Esempio n. 2
0
        public IActionResult Create(Loan item)
        {
            _context.LoanItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetLoan", new { id = item.Id }, item));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Address,Balance")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "ID,DateOfPayment,AmountOfPayment,Remarks")] LoanPayment loanPayment)
        {
            if (ModelState.IsValid)
            {
                db.LoanPayments.Add(loanPayment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(loanPayment));
        }
        public ActionResult Create([Bind(Include = "ID,LoanStatusCode,DateContractStarts,DateContractEnds,InterestRate,LoanAmount,TermsAndCoditions")] LoanContract loanContract)
        {
            if (ModelState.IsValid)
            {
                db.LoanContracts.Add(loanContract);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LoanStatusCode = new SelectList(db.LoanStatuses, "LoanStatusCode", "LoanStatusCode", loanContract.LoanStatus);
            return(View(loanContract));
        }
Esempio n. 6
0
        public static int deleteLoans(List <int> ids)

        {
            try
            {
                using (var context = new LoanContext())

                {
                    var loans = context.Loans.Where(x => ids.Contains(x.Id));
                    foreach (var loan in loans)
                    {
                        context.Loans.Remove(loan);
                    }
                    context.SaveChanges();
                    return(1);
                }
            }

            catch (Exception e)

            {
                Console.Write(e);
                return(-1);
            }
        }
        private void loanPaymentPlanner(LoanItem loanItem)
        {
            int monthsLeft = loanItem.MonthLeft;

            decimal interestRate        = loanItem.Rate;
            decimal originalBalance     = loanItem.Balance;
            decimal remainingBalance    = originalBalance;
            decimal totalMonthlyPayment = getTotalMonthlyPayment(originalBalance, interestRate, monthsLeft); // equal amount is paid every month

            List <PaymentPlanItem> ppiList = new List <PaymentPlanItem>();

            //loops through all months given to repay loanItem and creates a full repayment plan.
            for (int month = 0; month < monthsLeft; month++)
            {
                decimal interestPayment  = getInterestPayment(remainingBalance, interestRate);
                decimal principalPayment = getPrincipalPayment(totalMonthlyPayment, interestPayment);
                //above this line is previous remainingBalance
                remainingBalance = getRemainingBalance(remainingBalance, principalPayment);
                PaymentPlanItem ppi = new PaymentPlanItem(loanItem.Id, month + 1, interestPayment, principalPayment, remainingBalance);

                ppiList.Add(ppi);
            }

            _context.PaymentPlanItems.AddRange(ppiList);
            _context.SaveChanges();
        }
Esempio n. 8
0
        public LoanController(LoanContext ctx)
        {
            _context = ctx;

            if (_context.Loans.Count() == 0)
            {
                _context.Loans.Add(new Loan()
                {
                    BorrowerName = "James", FundingAmount = 10000, RepaymentAmount = 11200
                });
                _context.Loans.Add(new Loan()
                {
                    BorrowerName = "Bill", FundingAmount = 1500, RepaymentAmount = 1600
                });
                _context.Loans.Add(new Loan()
                {
                    BorrowerName = "Johan", FundingAmount = 20000, RepaymentAmount = 22000
                });
                _context.Loans.Add(new Loan()
                {
                    BorrowerName = "Cris", FundingAmount = 600, RepaymentAmount = 690
                });
                _context.SaveChanges();
            }
        }
Esempio n. 9
0
        public void ConstructGraph_Add_Save_Delete()
        {
            var loan = SaveNewLoan();

            using (var context = new LoanContext())
            {
                var foundLoan = context.Set <Loan>()
                                .Include(o => o.Lender)
                                .Include(o => o.LenderContact)
                                .SingleOrDefault(o => o.Id == loan.Id);
                foundLoan.ShouldNotBeNull();
                foundLoan.Log("Find", context);
                context.StateShouldBe(foundLoan, Unchanged);

                context.Remove(foundLoan);
                foundLoan.Log("Remove", context);
                context.StateShouldBe(foundLoan, Deleted);
                context.StateShouldBe(foundLoan.Lender, Unchanged); //  not cascading delete
                context.StateShouldBe(foundLoan.LenderContact, Unchanged);

                context.SaveChanges();
                foundLoan.Log("SaveChanged", context);
                context.StateShouldBe(foundLoan, Detached);
                context.StateShouldBe(foundLoan.Lender, Unchanged); //  not cascading delete
                context.StateShouldBe(foundLoan.LenderContact, Unchanged);
            }
        }
Esempio n. 10
0
        public LoanController(LoanContext profilecontext)
        {
            _profileContext = profilecontext;
            if (_profileContext.loans.Count() == 0)
            {
                //Profile 1
                _profileContext.loans.Add(new Loan
                {
                    username         = "******",
                    description      = "Members 1st Loans",
                    balance          = 35124.75,
                    lastActivityDate = DateTime.Now.ToString(),
                    paymentDueDate   = "09/24/2019",
                    minimumAmountDue = 344.90,
                });
                _profileContext.SaveChanges();

                //Profile 2
                _profileContext.loans.Add(new Loan
                {
                    username         = "******",
                    description      = "Members 1st Loans",
                    balance          = 884.70,
                    lastActivityDate = DateTime.Now.ToString(),
                    paymentDueDate   = "05/29/2019",
                    minimumAmountDue = 120.00,
                });
                _profileContext.SaveChanges();

                //Profile 3
                _profileContext.loans.Add(new Loan
                {
                    username         = "******",
                    description      = "Members 1st Checking Account",
                    balance          = 11000.50,
                    lastActivityDate = DateTime.Now.ToString(),
                    paymentDueDate   = "06/24/2019",
                    minimumAmountDue = 1070.25,
                });
                _profileContext.SaveChanges();
            }
        }
Esempio n. 11
0
 protected Thing SaveNewThing()
 {
     using (var context = new LoanContext())
     {
         var thing = new Thing();
         context.Update(thing);
         context.StateShouldBe(thing, Added);
         context.SaveChanges();
         context.StateShouldBe(thing, Unchanged);
         return(thing);
     }
 }
Esempio n. 12
0
        public LoanController(LoanContext context)
        {
            _context = context;

            if (_context.LoanFiles.Count() == 0)
            {
                _context.LoanFiles.Add(new LoanFile {
                    BorrowerName = "NewBorrower"
                });
                _context.SaveChanges();
            }
        }
Esempio n. 13
0
        public void Save_Update_SingleObject()
        {
            var thing = SaveNewThing();

            using (var context = new LoanContext())
            {
                context.StateShouldBe(thing, Detached);
                context.Update(thing);
                context.StateShouldBe(thing, Modified);

                context.SaveChanges(); // will update db even no real changes
                context.StateShouldBe(thing, Unchanged);
            }
        }
Esempio n. 14
0
        public void Save_Linq_Include_Update_Graph()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var xferLoan = SaveNewLoanExAndDetach();

            using (var context = new LoanContext())
            {
                // for the analogous Loan test, this throws since Lender in graph twice
                context.Update(xferLoan);
                context.StateShouldBe(xferLoan, Modified);

                context.SaveChanges(); // updates only Loans since others null
                context.StateShouldBe(xferLoan, Unchanged);
            }
        }
Esempio n. 15
0
 protected LoanEx SaveNewLoanEx()
 {
     using (var context = new LoanContext())
     {
         var loan = new LoanEx(childrenToo: true);
         context.Update(loan);
         context.StateShouldBe(loan, Added);
         context.StateShouldBe(loan.Lender, Added);
         context.StateShouldBe(loan.LenderContact, Added);
         context.SaveChanges();
         context.StateShouldBe(loan, Unchanged);
         context.StateShouldBe(loan.Lender, Unchanged);
         context.StateShouldBe(loan.LenderContact, Unchanged);
         return(loan);
     }
 }
Esempio n. 16
0
        public void Construct_Attach_Save_SingleObject()
        {
            using (var context = new LoanContext())
            {
                var thing = new Thing();
                thing.Log("Constructed", context);
                context.StateShouldBe(thing, Detached);

                context.Attach(thing);
                thing.Log("Attached", context);
                context.StateShouldBe(thing, Added);

                context.SaveChanges();
                thing.Log("SaveChanges", context);
                context.StateShouldBe(thing, Unchanged);
            }
        }
Esempio n. 17
0
 public static int AddLoan(Loan loan)
 {
     try
     {
         using (var context = new LoanContext())
         {
             context.Loans.Add(loan);
             context.SaveChanges();
             return(loan.Id);
         }
     }
     catch (Exception e)
     {
         Console.Write(e);
         return(-1);
     }
 }
        public void Construct_Update_Save()
        {
            using (var context = new LoanContext())
            {
                var thing = new Thing();
                thing.Log("Constructed", context);
                context.StateShouldBe(thing, Detached);

                context.Update(thing);
                thing.Log("Updated", context);
                context.StateShouldBe(thing, Added);

                context.SaveChanges();
                thing.Log("SaveChanges", context);
                context.StateShouldBe(thing, Unchanged);
            }
        }
Esempio n. 19
0
        public void Save_Find_Delete_SingleObject()
        {
            var thing = SaveNewThing();

            using (var context = new LoanContext())
            {
                var foundThing = context.Find <Thing>(thing.Id);
                foundThing.ShouldNotBeNull();
                foundThing.Log("Find", context);
                context.StateShouldBe(foundThing, Unchanged);

                context.Remove(foundThing);
                context.StateShouldBe(foundThing, Deleted);

                context.SaveChanges();
                context.StateShouldBe(foundThing, Detached);
            }
        }
Esempio n. 20
0
        public void Save_Find_Update_SingleObject()
        {
            var thing = SaveNewThing();

            using (var context = new LoanContext())
            {
                var foundThing = context.Find <Thing>(thing.Id);
                foundThing.ShouldNotBeNull();
                foundThing.Log("Find", context);
                context.StateShouldBe(foundThing, Unchanged);

                foundThing.Name = "Peoria";
                context.StateShouldBe(foundThing, Modified);

                context.SaveChanges();
                context.StateShouldBe(foundThing, Unchanged);
            }
        }
Esempio n. 21
0
        public void Save_Find_Update_Graph()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var loan = SaveNewLoan();

            using (var context = new LoanContext())
            {
                var foundLoan = context.Find <Loan>(loan.Id);
                foundLoan.ShouldNotBeNull();
                foundLoan.Log("Find", context);
                context.StateShouldBe(foundLoan, Unchanged);
                foundLoan.Name = "Peoria";
                context.StateShouldBe(foundLoan, Modified);
                context.SaveChanges();
                context.StateShouldBe(foundLoan, Unchanged);
                foundLoan = context.Find <Loan>(loan.Id);
                foundLoan.Name.ShouldBe("Peoria");
            }
        }
        public void Construct_WithExisting_Children_SetState()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);

            var xferLoan = SaveNewLoanAndDetach();
            var loan     = new Loan
            {
                Lender        = xferLoan.Lender,
                LenderContact = xferLoan.LenderContact
            };

            using (var context = new LoanContext())
            {
                loan.Log("Constructed with existing children", context);
                context.LoanGraphStateShouldBe(loan, Detached);

                context.Entry(loan).State = Added;
                loan.Log("State Set", context);
                context.StateShouldBe(loan, Added);
                context.StateShouldBe(loan.Lender, Detached);
                context.StateShouldBe(loan.LenderContact, Detached);

                context.SaveChanges(); // inserts into only Loans table
                context.StateShouldBe(loan, Unchanged);
                context.StateShouldBe(loan.Lender, Detached);
                context.StateShouldBe(loan.LenderContact, Detached);
            }

            using (var context = new LoanContext())
            {
                var foundLoan = context.Set <Loan>()
                                .Include(o => o.Lender)
                                .Include(o => o.LenderContact)
                                .SingleOrDefault(o => o.Id == loan.Id);
                foundLoan.ShouldNotBeNull();
                foundLoan.Lender.ShouldNotBeNull();
                foundLoan.LenderContact.ShouldNotBeNull();
                foundLoan.Lender.Id.ShouldBe(loan.Lender.Id);
                foundLoan.LenderContact.Id.ShouldBe(loan.LenderContact.Id);
                ReferenceEquals(foundLoan.Lender, foundLoan.LenderContact.Lender).ShouldBeTrue();
            }
        }
Esempio n. 23
0
        public IActionResult LendMoney(int BorrowerId, int MoneyLent)
        {
            ViewBag.UserName = HttpContext.Session.GetString("UserName");
            ViewBag.UserId   = HttpContext.Session.GetInt32("UserId");

            Loan newLoan = new Loan
            {
                Amount     = MoneyLent,
                LenderId   = (int)HttpContext.Session.GetInt32("UserId"),
                BorrowerId = BorrowerId,
                CreatedAt  = DateTime.Now,
                UpdatedAt  = DateTime.Now,
            };

            //detract from the user balance here? should be fine...
            //or calculate it later! get the count of all their donations and just subtract loll ez.
            _context.Add(newLoan);
            _context.SaveChanges();
            return(RedirectToAction("GetLender", new { LenderId = (int)HttpContext.Session.GetInt32("UserId") }));
        }
Esempio n. 24
0
        public void Save_Linq_Include_SetState_Graph()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);

            var xferLoan = SaveNewLoanAndDetach();

            using (var context = new LoanContext())
            {
                context.Entry(xferLoan).State = Modified;
                xferLoan.Log("After set State on root", context);
                context.StateShouldBe(xferLoan, Modified);
                context.StateShouldBe(xferLoan.Lender, Detached);
                context.StateShouldBe(xferLoan.LenderContact, Detached);

                context.SaveChanges();
                context.StateShouldBe(xferLoan, Unchanged);
                context.StateShouldBe(xferLoan.Lender, Detached);
                context.StateShouldBe(xferLoan.LenderContact, Detached);
            }
        }
Esempio n. 25
0
        public void Update_Thing()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var thing = SaveNewThingAndDetach();

            using (var context = new LoanContext())
            {
                context.Update(thing);
                context.StateShouldBe(thing, Modified);

                thing.Name = "Peoria";
                context.StateShouldBe(thing, Modified);
                context.SaveChanges();
            }
            using (var context = new LoanContext())
            {
                thing = context.Set <Thing>().Find(thing.Id);
                thing.ShouldNotBeNull();
                thing.Name.ShouldBe("Peoria");
            }
        }
Esempio n. 26
0
        public void Throw_Add_Duplicate_Thing()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var thing = SaveNewThingAndDetach();

            using (var context = new LoanContext())
            {
                context.Add(thing);
                context.StateShouldBe(thing, Added);

                try
                {
                    context.SaveChanges();
                    true.ShouldBeFalse();
                }
                catch (DbUpdateException)
                {
                    true.ShouldBeTrue(); // duplicate key since already there.
                }
            }
        }
Esempio n. 27
0
        public void ConstructGraph_Attach_Save()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            using (var context = new LoanContext())
            {
                var loan = new Loan(childrenToo: true);
                loan.Log("Constructed", context);
                context.LoanGraphStateShouldBe(loan, Detached);

                context.Attach(loan);
                loan.Log("Attach after constructed", context);
                context.LoanGraphStateShouldBe(loan, Added);

                context.SaveChanges();
                loan.Log("SaveChanges", context);
                context.LoanGraphStateShouldBe(loan, Unchanged);
                loan.Id.ShouldNotBe(Guid.Empty);
                loan.Lender.Id.ShouldNotBe(Guid.Empty);
                loan.LenderContact.Id.ShouldNotBe(Guid.Empty);
                loan.LenderContact.Lender.Id.ShouldBe(loan.Lender.Id);
            }
        }
        public void ConstructGraph_Attach_SetState()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            using (var context = new LoanContext())
            {
                var loan = new Loan(childrenToo: true);
                loan.Log("Constructed", context);
                context.LoanGraphStateShouldBe(loan, Detached);

                context.Attach(loan).State = Unchanged; // Attach set graph to Added
                loan.Log("Attach and State set", context);
                context.StateShouldBe(loan, Unchanged);
                context.StateShouldBe(loan.Lender, Added);
                context.StateShouldBe(loan.LenderContact, Added);

                context.SaveChanges(); // inserts into 3 tables
                loan.Log("SaveChanges", context);
                context.LoanGraphStateShouldBe(loan, Unchanged);
                loan.Id.ShouldNotBe(Guid.Empty);
                loan.Lender.Id.ShouldNotBe(Guid.Empty);
                loan.LenderContact.Id.ShouldNotBe(Guid.Empty);
                loan.LenderContact.Lender.Id.ShouldBe(loan.Lender.Id);
            }
        }
Esempio n. 29
0
 public void AddUser(User user)
 {
     _dbContext.Add(user);
     _dbContext.SaveChanges();
 }
Esempio n. 30
0
 public void AddLoan(Loan loan)
 {
     _dbContext.Loans.Add(loan);
     _dbContext.SaveChanges();
 }