public ActionResult Login(Users post) { if (ModelState.IsValid) { using (var db = new UsersDatabase()) { Users Uid = db.UsersDatabse.Where(p => p.Username == post.Username && p.Password == post.Password).FirstOrDefault(); if (Uid != null) { Session["CurrentUser"] = Uid; if (Uid.IsAdmin == true) { Session["IsAdmin"] = true; } return RedirectToRoute(new { controller = "Home", Action = "Index" }); } else { ViewBag.Message = "Vi kunne desvære ikke log dig ind. prøv igen."; } } } return View(); }
public ActionResult CreateUser(Users post) { if (ModelState.IsValid) { using (var db = new UsersDatabase()) { //Save to DB post.DateCreated = DateTime.Now; post.IsAdmin = false; db.UsersDatabse.Add(post); db.SaveChanges(); } TempData["RegisterUser"] = post; //Redirect return RedirectToAction("UserCreated"); } return View(); }