コード例 #1
0
 //
 // GET: /Accounts/
 //Index Action Method
 public ActionResult Index()
 {
     using (SiteContext db = new SiteContext())
     {
         return View(db.Users.ToList());
     }
 }
コード例 #2
0
 public ActionResult Login(User user)
 {
     using (SiteContext db = new SiteContext())
     {
         // lambda expression to compare that compares the variable on the website to the one stored in the database
         var usr = db.Users.Single(u => u.Email == user.Email && u.Password == user.Password);
         //if the 'user' var is not null..
         if (usr != null)
         {
             //convert to string and transfer data to session variable
             Session["UserID"] = usr.UserID.ToString();
             Session["Email"] = usr.Email.ToString();
             //Transfer page to 'LoggedIn' page
             return RedirectToAction("LoggedIn");
         }
         //if there is a probelm
         else
         {
             //display error msg
             ModelState.AddModelError("", "Email or Password is incorrect.");
         }
     }
     return View();
 }
コード例 #3
0
 public ActionResult Register(User account)
 {
     //if the modelstate is valid
     if (ModelState.IsValid)
     {
         using (SiteContext db = new SiteContext())
         {
             //add a user
             db.Users.Add(account);
             //save the details entered
             db.SaveChanges();
         }
         ModelState.Clear();
         //display success message
         ViewBag.Message = account.FirstName + "" + account.LastName + " successfully registered.";
     }
     return View();
 }