[HttpPost]// thuc hien dang nhap public ActionResult VerifyLogin(User user) { // kiem tra du lieu nhap if (ModelState.IsValid) { // truy van csdl string uid = null; using (var _context = new DA_QLTMDTEntities()) { // query id tu email va password de kiem tra dang nhap try { var id = (from u in _context.Users where u.Email == user.Email && u.Password == user.Password select u).FirstOrDefault(); uid = id.ToString(); } catch { } } if (uid != null) { mydb.closeConnection(); return(View("LoginSuccess")); } else { mydb.closeConnection(); return(View("Error")); } } return(View("Login")); }
public string GetUserIDbyEmail(string email) { string uid = default; using (var _context = new DA_QLTMDTEntities()) { // query id tu email va password de kiem tra dang nhap try { var id = (from u in _context.Users where u.Email == email select u).FirstOrDefault(); uid = id.ToString(); } catch { } } return(uid); }
[HttpPost] // thuc hien dang ki public ActionResult RegisterUser(User user) { // lay id cua user tu email string uid = null; // kiem tra du lieu nhap if (ModelState.IsValid) { using (var _context = new DA_QLTMDTEntities()) { try { var id = (from u in _context.Users where u.Email == user.Email select u).FirstOrDefault(); uid = id.ToString(); } catch { } if (uid == null) { //Response.Write("<script>alert('Data inserted successfully')</script>"); try { mydb.openConnection(); SqlCommand command = new SqlCommand("INSERT INTO Users (Name,Email,Password) Values( '" + user.Name + "', '" + user.Email + "','" + user.Password + "')", mydb.getConnection); command.ExecuteNonQuery(); mydb.closeConnection(); Response.Write("<script>alert('Data inserted successfully')</script>"); return(View("LoginSuccess")); } catch { return(View()); } } else { // Response.Write("<script>alert('Data inserted successfully')</script>"); return(View("Error")); } } } return(View("Register")); }