public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new UserDao(); var resultadmin = dao.AdminLogin(model.userName, model.passWord); var resultuser = dao.UserLogin(model.userName, model.passWord); if (resultuser == true) { var user = dao.GetById(model.userName); var userSession = new UserLogin(); userSession.UserName = user.username; userSession.UserID = user.uid; Session.Add(CommonConstants.USER_SESSION, userSession); return(View("UserPage")); } if (resultadmin == true) { var user = dao.GetById(model.userName); var userSession = new UserLogin(); userSession.UserName = user.username; userSession.UserID = user.uid; Session.Add(CommonConstants.USER_SESSION, userSession); return(View("AdminPage")); } else { ModelState.AddModelError("", "Login Fail"); } } return(View("Index")); }
public ActionResult Login(AdminLoginModel model) { if (ModelState.IsValid) { var dao = new UserDao(); var result = dao.AdminLogin(model.UserName, model.Password); if (result == true) { var admin = dao.GetAdminByUserName(model.UserName); var adminSession = new AdminLoginModel(); adminSession.UserName = admin.UserName; adminSession.UserID = admin.ID; adminSession.Password = admin.Password; Session.Add(CommonConstants.ADMIN_SESSION, adminSession); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Sai tài khoản hoặc mật khẩu."); } } return(View(model)); }