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 void Construct_Add_Save_SingleObject()
        {
            using (var context = new LoanContext())
            {
                var thing = new Thing();
                thing.Log("Constructed", context);
                context.StateShouldBe(thing, Detached);

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

                context.SaveChanges();
                thing.Log("SaveChanges", context);
                context.StateShouldBe(thing, Unchanged);
            }
        }
Esempio n. 3
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. 4
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. 5
0
        public void ConstructGraph_Add_Save()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            using (var context = new LoanContext())
            {
                var loan = new Loan(childrenToo: true);
                loan.Lender.ShouldNotBeNull();
                context.LoanGraphStateShouldBe(loan, Detached);

                context.Add(loan);
                loan.Log("Add", 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);
            }
        }
Esempio n. 6
0
 public void AddUser(User user)
 {
     _dbContext.Add(user);
     _dbContext.SaveChanges();
 }