public ActionResult CreateUser(EMS_User u) { // replace SecurityLevel_ID to ScurityDescription. ViewBag.SecurityLevel_ID = new SelectList(db.EMS_SecurityLevel, "SecurityLevel_ID", "ScurityDescription"); // is model state. if (ModelState.IsValid) { // add new user into database. db.EMS_Users.Add(u); // save change. db.SaveChanges(); return(RedirectToAction("LogIn", "LogIn")); } // return view layer. return(View("Index")); }
public ActionResult LogIn(EMS_User u) { // this action is for handle post. if (ModelState.IsValid) // this is check validity. { using (EMS_PSS_DBContext dt = new EMS_PSS_DBContext()) { // check database to see if this user in database. var v = dt.EMS_Users.Where(s => s.User_Name.Equals(u.User_Name) && s.PassWord.Equals(u.PassWord)).FirstOrDefault(); // if user is exist. if (v != null) { // set info to session. Session["LogedUserID"] = v.User_ID.ToString(); Session["LogedUserName"] = v.User_Name.ToString(); Session["LogedSecurityLevel"] = v.SecurityLevel_ID.ToString(); return(RedirectToAction("AfterLogin")); } } } // return view. return(View(u)); }