コード例 #1
0
 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"));
     }
 }
コード例 #2
0
        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"));
        }
コード例 #3
0
 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"));
 }
コード例 #4
0
        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"));
        }
コード例 #5
0
        public IActionResult Create(Typedeposit typedeposit)
        {
            db.Typesdeposits.Add(typedeposit);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public IActionResult Create(Depositor depositor)
        {
            db.Depositors.Add(depositor);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #7
0
        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}"));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
 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"));
     }
 }
コード例 #10
0
ファイル: CustomerManager.cs プロジェクト: AhmadBasha/ASP.NET
        public int Add(Customer customer)
        {
            _context.Customers.Add(customer);
            _context.SaveChanges();

            return(customer.CustomerID);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
ファイル: BillPayManager.cs プロジェクト: AhmadBasha/ASP.NET
        public int Add(BillPay billPay)
        {
            _context.BillPays.Add(billPay);
            _context.SaveChanges();

            return(billPay.BillPayID);
        }
コード例 #13
0
ファイル: AccountManager.cs プロジェクト: AhmadBasha/ASP.NET
        public int Add(BaseAccount account)
        {
            _context.Accounts.Add(account);
            _context.SaveChanges();

            return(account.AccountNumber);
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        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"));
        }
コード例 #16
0
        public int Add(Transaction transaction)
        {
            _context.Transactions.Add(transaction);
            _context.SaveChanges();

            return(transaction.TransactionID);
        }
コード例 #17
0
        [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);
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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"));
            }
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        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));
        }
コード例 #23
0
 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"));
     }
 }
コード例 #24
0
        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));
        }
コード例 #25
0
        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"));
            }
        }
コード例 #26
0
 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"));
     }
 }
コード例 #27
0
        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());
        }
コード例 #28
0
        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();
            }
        }
コード例 #29
0
        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"));
        }
コード例 #30
0
        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");
        }