コード例 #1
0
        public ActionResult Register(UserAccount account)
        {
            if (ModelState.IsValid)
            {
                using (AccountDbContext db = new AccountDbContext())
                {
                    db.userAccount.Add(account);
                    db.SaveChanges();
                }

                ModelState.Clear();
                ViewBag.Message = account.FristName + " " + account.LastName + "  Congratulations, you are sucessfully registered.";

            }
            return View();
        }
コード例 #2
0
        public ActionResult Login(UserAccount user)
        {
            using (AccountDbContext db = new AccountDbContext())
            {
                var usr = db.userAccount.Single(u => u.Username == user.Username && u.Password == user.Password);
                if (usr != null)
                {
                    Session["UserID"] = user.UserID.ToString();
                    Session["Username"] = user.Username.ToString();
                    return RedirectToAction("LoggedIn");
                }
                else
                {
                    ModelState.AddModelError("","The username or password you have entered is incorrect, please try again.");

                }
            }

            return View();
        }