public IActionResult Login(UserModel user) { if (user.fUsername != null && user.fPassword != null) { UserDBModel db = new UserDBModel(); UserModel luser = db.UserLogin(user.fUsername, user.fPassword); if (luser.fUsername != null) { Response.Cookies.Append("user", luser.fUsername); Response.Cookies.Append("userID", luser.fID); if (db.AdminChecking(luser.fUsername, luser.fPassword)) { string id = luser.fID; return(Redirect(@"../Admin/Index/?id=" + id)); } return(Redirect("../Home/Index/?id=" + luser.fID)); } else { ModelState.AddModelError("", "Wrong username or password"); } } else { ModelState.AddModelError("", "should not empty username or password"); } return(RedirectToAction("../User/Login/")); }
public IActionResult Index(string id = "0") { UserDBModel db = new UserDBModel(); if (Request.Cookies["userID"] != null) { id = Request.Cookies["userID"]; } UserModel user = db.GetUserById(Int32.Parse(id)); List <UserModel> nv = db.GetAllUser(user.fUsername, user.fPassword); if (!db.AdminChecking(Int32.Parse(id))) { return(RedirectToAction("../Home/Index")); } return(View(nv)); }