public ActionResult Validate(TblTaiKhoan admin) { var _admin = _context.TblTaiKhoan.Where(s => s.TenDangNhap == admin.TenDangNhap && s.MaQuyen == 2); if (_admin.Any()) { if (_admin.Where(s => s.MatKhau == admin.MatKhau).Any()) { var check = _context.TblKhachHang.Where(x => x.MaTk == _admin.Select(y => y.MaTk).FirstOrDefault()).Select(z => z.MaKh).FirstOrDefault(); var checkName = _context.TblKhachHang.Where(x => x.MaTk == _admin.Select(y => y.MaTk).FirstOrDefault()).Select(z => z.HoTen).FirstOrDefault(); HttpContext.Session.SetString(SessionName, checkName); HttpContext.Session.SetInt32(SessionID, check); return(Json(new { status = true, message = checkName })); } else { return(Json(new { status = false, message = "Sai mật khẩu!" })); } } else { return(Json(new { status = false, message = "Sai tài khoản!" })); } }
public async Task <IActionResult> Edit(int id, [Bind("MaTk,TenDangNhap,MatKhau,MaQuyen")] TblTaiKhoan tblTaiKhoan) { if (id != tblTaiKhoan.MaTk) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tblTaiKhoan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblTaiKhoanExists(tblTaiKhoan.MaTk)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MaQuyen"] = new SelectList(_context.TblQuyen, "MaQuyen", "TenQuyen", tblTaiKhoan.MaQuyen); return(View(tblTaiKhoan)); }