public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (dbContext.users.Any(u => u.Email == newUser.Email)) { ModelState.AddModelError("Email", "Email is already in use!"); return(View("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); newUser.Password = Hasher.HashPassword(newUser, newUser.Password); dbContext.Add(newUser); dbContext.SaveChanges(); if (HttpContext.Session.GetInt32("UserId") == null) { HttpContext.Session.SetInt32("UserId", newUser.UserId); } return(RedirectToAction("Success", newUser.UserId)); } } else { System.Console.WriteLine("*******************"); System.Console.WriteLine("REGISTRATION NOT WORKING!!!!"); System.Console.WriteLine("*******************"); return(View("Index")); } }
public IActionResult RegisterUser(RegisterUser newUser) { if (_context.Users.Where(user => user.Email == newUser.Email).SingleOrDefault() != null) { ModelState.AddModelError("Email", "Email already in use"); } PasswordHasher <RegisterUser> hasher = new PasswordHasher <RegisterUser>(); if (ModelState.IsValid) { User theUser = new User { FirstName = newUser.FirstName, LastName = newUser.LastName, Email = newUser.Email, Password = hasher.HashPassword(newUser, newUser.Password), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; User loggedUser = _context.Add(theUser).Entity; _context.SaveChanges(); HttpContext.Session.SetInt32("id", loggedUser.UserId); return(Redirect($"/Dashboard/{loggedUser.UserId}")); } ; return(View("Index")); }
public IActionResult Register(RegisterViewModel reg) { if (ModelState.IsValid) { List <User> u = _context.Users.Where(x => x.Email == reg.Email).ToList(); if (u.Count == 0) { // Console.WriteLine($"****{reg.Email} was not in db, need to add "); User x = new User(reg.First, reg.Last, reg.Email, reg.Password); _context.Add(x); _context.SaveChanges(); HttpContext.Session.SetString("username", x.First); HttpContext.Session.SetInt32("userid", x.Id); Account a = new Account(0, x.Id); _context.Add(a); _context.SaveChanges(); string address = $"account/{x.Id}"; return(Redirect(address)); } else { ModelState.AddModelError("Email", $"{reg.Email} already registered"); } } return(View("register")); }
public ActionResult Create(Teacher model) { if (ModelState.IsValid) { try { var userProfile = db.UserProfiles.Local.SingleOrDefault(u => u.UserName == User.Identity.Name) ?? db.UserProfiles.SingleOrDefault(u => u.UserName == User.Identity.Name); if (userProfile != null) { var teacher = new Teacher { UserProfile = userProfile, FirstName = model.FirstName, LastName = model.LastName, }; db.Teachers.Add(teacher); db.SaveChanges(); return(RedirectToAction("Index", "Teacher")); } } catch (DataException) { ModelState.AddModelError("", "Something went wrong, try again."); } } //Something failed, redisplay form return(RedirectToAction("Create", "Teacher")); }
public IActionResult Create(Typedeposit typedeposit) { db.Typesdeposits.Add(typedeposit); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Depositor depositor) { db.Depositors.Add(depositor); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Transaction(float amount, int id) { User currUser = _context.users.SingleOrDefault(user => user.userid == id); float balance = currUser.balance; if ((balance += amount) < 0) { TempData["exceed"] = "Cannot withdraw more than Current Balance"; return(Redirect($"/account/{currUser.userid}")); } Transaction newTrans = new Transaction { amount = amount, userid = id, date = DateTime.Now }; _context.transactions.Add(newTrans); _context.SaveChanges(); currUser.balance += amount; _context.SaveChanges(); return(Redirect($"/account/{currUser.userid}")); }
public ActionResult Create([Bind(Include = "ID,Number,MyProperty,Balance,ProfileID,CreditCardID")] BankAccount bankAccount) { if (ModelState.IsValid) { bankAccount.Profile = db.Profiles.Single(e => e.UserName == User.Identity.Name); StringBuilder numb = new StringBuilder(); string generated; Random rand = new Random(); do { for (int i = 0; i < 26; ++i) { numb.Append(rand.Next(0, 9)); } generated = numb.ToString(); } while (db.BankAccounts.Any(e => e.Number == generated)); bankAccount.Number = generated; db.BankAccounts.Add(bankAccount); db.SaveChanges(); return(RedirectToAction("MyList")); } ViewBag.CreditCardID = new SelectList(db.CreditCards, "ID", "Image", bankAccount.CreditCardID); ViewBag.ProfileID = new SelectList(db.Profiles, "ID", "UserName", bankAccount.ProfileID); return(View(bankAccount)); }
public IActionResult Register(RegisterViewModel user) { if (ModelState.IsValid) { PasswordHasher <RegisterViewModel> Hasher = new PasswordHasher <RegisterViewModel>(); user.password = Hasher.HashPassword(user, user.password); Users User = new Users() { first_name = user.first_name, last_name = user.last_name, email = user.email, password = user.password, created_at = DateTime.Now, updated_at = DateTime.Now }; // List<Users> Users = _context.users.Include(p => p.accounts).ToList(); _context.Add(User); _context.SaveChanges(); return(RedirectToAction("Status")); } else { return(View("index")); } }
public int Add(Customer customer) { _context.Customers.Add(customer); _context.SaveChanges(); return(customer.CustomerID); }
public IHttpActionResult PutKlant(int id, Klant klant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != klant.KlantID) { return(BadRequest()); } db.Entry(klant).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!KlantExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public int Add(BillPay billPay) { _context.BillPays.Add(billPay); _context.SaveChanges(); return(billPay.BillPayID); }
public int Add(BaseAccount account) { _context.Accounts.Add(account); _context.SaveChanges(); return(account.AccountNumber); }
public IHttpActionResult PutRekening(int id, Rekening rekening) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != rekening.RekeningNr) { return(BadRequest()); } db.Entry(rekening).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RekeningExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Status(int?id, string status) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Credit credit = db.Credits.Find(id); if (credit != null) { if (credit.CreditType == CreditType.AWAITING) { if (status == "acc") { credit.BankAccount.Balance += credit.BaseBalance; credit.CreditType = CreditType.ACCEPTED; } else if (status == "rej") { credit.CreditType = CreditType.REJECTED; } } credit.StatusDate = DateTime.Now; } db.SaveChanges(); return(RedirectToAction("Index")); }
public int Add(Transaction transaction) { _context.Transactions.Add(transaction); _context.SaveChanges(); return(transaction.TransactionID); }
[Test] // 1 public void AddBankAccount_AddsANewAccountAnd_ReturnsNewAccountId_WhenCalled() { //Arrange BankAccount bankAccount = new BankAccount { CustomerId = 1, BankAccountTypeId = 1, Interestrate = 0 }; BankAccountRepository bankAccountRepository = new BankAccountRepository(context); var expected1 = bankAccount; BankAccountType bankAccountType1 = new BankAccountType { BankAccountTypeId = 1, BankAccountTypeName = "Saving Account" }; BankAccountType bankAccountType2 = new BankAccountType { BankAccountTypeId = 2, BankAccountTypeName = "Check Account" }; context.BankAccountTypes.Add(bankAccountType1); context.BankAccountTypes.Add(bankAccountType2); context.SaveChanges(); int expected2 = 1; //Act int actual2 = bankAccountRepository.AddBankAccount(bankAccount); var actual1 = context.BankAccounts.ToList().ElementAt(0); //Assert Assert.AreEqual(expected1, actual1); Assert.AreEqual(expected2, actual2); }
public ActionResult Create(Account account) { account.DateOpened = DateTime.Today; account.IsActive = true; account.Balance = 0; if (account.Type == "Checking") { account.InterestRate = 0.06m; } else if (account.Type == "Term Deposit") { account.InterestRate = 2.55m; account.Balance = 5000; } if (ModelState.IsValid) { db.Accounts.Add(account); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(account)); }
public IActionResult register(IndexViewModel user) { User regUser = user.NewRegUser; // Check initial ModelState if (ModelState.IsValid) { // If a User exists with provided email if (dbContext.Users.Any(u => u.Email == regUser.Email)) { ModelState.AddModelError("regUser.Email", "Email already registered!"); return(RedirectToAction("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); regUser.Password = Hasher.HashPassword(regUser, regUser.Password); // Add the user to database here dbContext.Add(regUser); dbContext.SaveChanges(); HttpContext.Session.SetString("UserEmail", regUser.Email); return(RedirectToAction("Accounts")); } } else { return(View("Index")); } }
public ActionResult Create([Bind(Include = "ID,CreditAmount,NumberOfMonths,TypeID")] CreditApplication creditApplication) { if (ModelState.IsValid) { HttpPostedFileBase file = Request.Files["ScannedDocument"]; if (file.ContentLength != 0) { Image image = Image.FromStream(file.InputStream, true, true); creditApplication.ScannedDocument = imageToByteArray(image); } creditApplication.TotalRepayment = GetMonthRepayment(creditApplication.CreditAmount, creditApplication.NumberOfMonths, creditApplication.TypeID) * creditApplication.NumberOfMonths; creditApplication.MonthRepayment = GetMonthRepayment(creditApplication.CreditAmount, creditApplication.NumberOfMonths, creditApplication.TypeID); creditApplication.DateOfSubmission = DateTime.Now; creditApplication.State = null; db.CreditApplications.Add(creditApplication); db.Profiles.Single(p => p.Email == User.Identity.Name).CreditApplications.Add(creditApplication); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Types = db.CreditTypes.ToList(); return(View(creditApplication)); }
public IHttpActionResult PutTransactie(int id, Transactie transactie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != transactie.TransactieID) { return(BadRequest()); } db.Entry(transactie).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TransactieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutPas(string id, Pas pas) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pas.PasID) { return(BadRequest()); } db.Entry(pas).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PasExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { User CheckUser = _context.Users.SingleOrDefault(u => u.Email == model.Email); if (CheckUser != null) { TempData["EmailInUseError"] = "Email Aleady in use"; return(View("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); User user = new User() { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, created_at = DateTime.Now }; user.Password = Hasher.HashPassword(user, model.Password); _context.Add(user); _context.SaveChanges(); HttpContext.Session.SetInt32("currentUserId", user.UserId); HttpContext.Session.SetString("currentFirstName", user.FirstName); return(RedirectToAction("Dashboard")); } } else { return(View("Index")); } }
public ActionResult NewTrans([Bind(Include = "ID,TransactionDate,FromID,ToID,Amount,Defined,Title")] Transaction transaction) { if (ModelState.IsValid) { transaction.Defined = false; transaction.TransactionDate = DateTime.Now; BankAccount fr = db.BankAccounts.Single(e => e.ID == transaction.FromID); BankAccount target = db.BankAccounts.Single(e => e.ID == transaction.ToID); if (fr.Balance < transaction.Amount) { return(RedirectToAction("Index")); } target.Balance += transaction.Amount; fr.Balance -= transaction.Amount; db.Transactions.Add(transaction); db.SaveChanges(); Profile current = db.Profiles.Single(e => e.UserName == User.Identity.Name); if (current.EnableMail) { SendMail(target.Profile.UserName, "You received transfer", "You have new transaction. Visit us to check. Virtual bank"); } db.Entry(transaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FromID = new SelectList(db.BankAccounts, "ID", "Number", transaction.FromID); ViewBag.ToID = new SelectList(db.BankAccounts, "ID", "Number", transaction.ToID); return(View(transaction)); }
public IActionResult Submit(regvalidate NewUser) { if (TryValidateModel(NewUser)) { DateTime now = DateTime.Now; User New = new User { first = NewUser.FirstName, last = NewUser.LastName, email = NewUser.Email, password = NewUser.Password, createdAt = DateTime.Now, ballance = 0, }; _context.Add(New); _context.SaveChanges(); //add session of user return(View("Account")); } else { Console.WriteLine("in else"); ViewBag.errors = ModelState.Values; Console.WriteLine(ViewBag.errors); return(View("login")); } }
public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (dbContext.Users.Any(u => u.Email == newUser.Email)) { ModelState.AddModelError("Email", "Email already registered!"); return(View("Index")); } else { PasswordHasher <User> hasher = new PasswordHasher <User>(); newUser.Password = hasher.HashPassword(newUser, newUser.Password); dbContext.Users.Add(newUser); dbContext.SaveChanges(); User justMade = dbContext.Users.FirstOrDefault(u => u.Email == newUser.Email); HttpContext.Session.SetInt32("LoggedId", justMade.UserId); HttpContext.Session.SetString("LoggedName", justMade.FirstName); return(RedirectToAction("Account", justMade.UserId)); } } else { return(View("Index")); } }
public ActionResult Create(RegisterViewModel model) { var userManager = new UserManager <ApplicationUser>( new UserStore <ApplicationUser>(new ApplicationDbContext())); if (ModelState.IsValid) { var worker = new ApplicationUser { UserName = model.Email }; userManager.Create(worker, model.Password); userManager.AddToRoleAsync(worker.Id, "Worker"); Address address = new Address { HouseNumber = model.HouseNumber, Street = model.Street, PostCode = model.PostalCode, City = model.City }; db.Addresses.Add(address); Profile profile = new Profile { Address = address, Name = model.Name, LastName = model.LastName, Email = model.Email, Pesel = model.PESEL, BirthDate = model.BirthDate, MothersName = model.MothersName }; db.Profiles.Add(profile); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public virtual void Correct(decimal amount, BankAccount bankAccount) { BankAccount account = bankContext.BankAccounts.Find(bankAccount.BankAccountId); int TypeId = account.BankAccountTypeId; if (TypeId == 1) { if (amount >= 0) { account.Balance = amount; bankContext.SaveChanges(); } else { throw new Exception("Overdraft not allowed"); } } if (TypeId == 2) { account.Balance = amount; bankContext.SaveChanges(); } }
public IActionResult RunTransaction(Transaction NewTransaction) { System.Console.WriteLine("adding newTransction"); NewTransaction.CreatedAt = DateTime.Now; var loggedUserId = HttpContext.Session.GetInt32("UserId"); var update_success = Update(NewTransaction.Amount); if (update_success) { NewTransaction.UserId = loggedUserId.Value; _context.Add(NewTransaction); _context.SaveChanges(); } else { System.Console.WriteLine(" ################In Else"); ViewBag.status = new List <string>() { "Invalid Amount" }; } return(RedirectToAction("show", "Home")); }
public IActionResult Register(User model) { if (ModelState.IsValid) { User CurrentUser = new User() { FirstName = model.FirstName, LastName = model.LastName, Password = model.Password, Email = model.Email, ConPassword = model.ConPassword, Balance = 400 }; //List<Dictionary<string, object>> User = _dbConnector.Query($"INSERT INTO users (first_name, last_name, email, password, age) VALUES ('{model.FirstName}', '{model.LastName}', '{model.Email}', '{model.Password}', 0)"); //userFactory.Add(CurrentUser); _bcontext.Add(CurrentUser); _bcontext.SaveChanges(); HttpContext.Session.SetObjectAsJson("cur_user", CurrentUser); return(RedirectToAction("Account")); } else { string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); Console.WriteLine(messages); HttpContext.Session.SetObjectAsJson("reg_errors", ModelState.Values); return(RedirectToAction("Index")); } //List<Dictionary<string, object>> Allq = _dbConnector.Query("SELECT * FROM quotes ORDER BY created_at Desc"); }