public ActionResult Dangky(TaiKhoan tk) { var NguoiDung = db.TaiKhoans.Where(x => x.Email == tk.Email).ToList(); if (NguoiDung.Count > 0) { Session["dangkyemail"] = true; return(Redirect("/Login/Index")); } TaiKhoan taikhoanmoi = new TaiKhoan(); MD5HASH md5Hash = new MD5HASH(); var mk = md5Hash.encrypt(tk.Matkhau); taikhoanmoi.Ten = tk.Ten; taikhoanmoi.Ho = tk.Ho; taikhoanmoi.Ngaysinh = tk.Ngaysinh; taikhoanmoi.Sdt = tk.Sdt; taikhoanmoi.Email = tk.Email; taikhoanmoi.Matkhau = mk; taikhoanmoi.Phanquyen = 0; db.TaiKhoans.Add(taikhoanmoi); db.SaveChanges(); Session["dangkythanhcong"] = true; return(Redirect("/Login/Index")); }
public ActionResult Dangnhap(TaiKhoan tk) { if (ModelState.IsValid) { MD5HASH md5Hash = new MD5HASH(); var mk = md5Hash.encrypt(tk.Matkhau); var NguoiDung = db.TaiKhoans.SingleOrDefault(x => x.Email == tk.Email && x.Matkhau == mk);//kiểm tra giá trị nhập vào if (NguoiDung != null) { Session["TaiKhoan"] = NguoiDung; Session["Admin"] = null; Session["Ten"] = NguoiDung.Ten; Session["TenDangNhap"] = NguoiDung.TenDangnhap; var giohang = db.giohangs.Where(x => x.makhachhang == NguoiDung.makh).ToList <giohang>(); List <sanpham> dsSanPham = new List <sanpham>(); foreach (var item in giohang) { sanpham sanpham = db.sanphams.Where(x => x.masp == item.masp && x.slsp >= item.soluongdamua && x.trangthai == 1).SingleOrDefault(); if (sanpham != null) { sanpham.slsp = item.soluongdamua; dsSanPham.Add(sanpham); } } if (dsSanPham.Count > 0) { Session["giohang"] = dsSanPham; } return(Redirect("/Home/Index")); } } Session["dangnhapsai"] = true; return(Redirect("/Login/Index")); }
public ActionResult Edit([Bind(Include = "makh,TenDangnhap,Ten,Ho,Ngaysinh,Sdt,Email,Matkhau,Phanquyen")] TaiKhoan taiKhoan) { if (ModelState.IsValid) { MD5HASH md5Hash = new MD5HASH(); var mk = md5Hash.encrypt(taiKhoan.Matkhau); taiKhoan.Matkhau = mk; db.Entry(taiKhoan).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(taiKhoan)); }
public ActionResult Dangnhap(TaiKhoan tk) { if (ModelState.IsValid) { MD5HASH md5Hash = new MD5HASH(); var mk = md5Hash.encrypt(tk.Matkhau); var Admin = db.TaiKhoans.SingleOrDefault(x => x.Email == tk.Email && x.Matkhau == mk && x.Phanquyen == 1); if (Admin != null) { Session["Admin"] = Admin.Phanquyen; Session["HoTen"] = Admin.Ten; Session["TenDangNhap"] = Admin.TenDangnhap; return(Redirect("/admin/Home")); } } Session["dangnhapAdminSai"] = true; return(Redirect("/admin/Login/Index")); }