public ActionResult XuLyLogin(Login model)
 {
     if (ModelState.IsValid)
     {
         var dao    = new DataAccessObject();
         var result = dao.Login(model.UserName, FileMaHoa.MD5Hash(model.Password));
         if (result == 1)
         {
             var user        = dao.GetByID(model.UserName);
             var userSession = new UserLogin();
             userSession.UserName = user.UserName;
             userSession.UserID   = user.ID;
             userSession.GroupID  = user.GroupID;
             var listPermission = dao.GetListPermission(model.UserName);
             Session.Add(CommonConstants.SESSION_PERMISSION, listPermission);
             Session.Add(CommonConstants.USER_SESSION, userSession);
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             if (result == -1)
             {
                 ModelState.AddModelError("", "Tài Khoản Không Tồn Tại!!!");
             }
             if (result == -2)
             {
                 ModelState.AddModelError("", "Mật Khẩu Không Đúng!!!");
             }
         }
     }
     return(View("DangNhap"));
 }
Пример #2
0
        public ActionResult Login(Login model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new DataAccessObject();
                var result = dao.LoginKH(model.TaiKhoan, FileMaHoa.MD5Hash(model.MatKhau));
                if (result == 1)
                {
                    var khachHang = dao.GetByID_KH(model.TaiKhoan);
                    Session.Add(CommonConstants.CUSTOMER_SESSION, khachHang.HoTen);
                    return(Redirect("/"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Tài Khoản Không Tồn Tại!!!");
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "Mật Khẩu Không Đúng!!!");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "Tài Khoản Đã Bị Khóa!!!");
                }
                model = new Login();
            }

            return(View(model));
        }
Пример #3
0
        public ActionResult Register(Register model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (csdl.KhachHangs.ToList().Exists(x => x.TaiKhoan.Trim() == model.TaiKhoan.Trim()))
                    {
                        ModelState.AddModelError("", "UserName already exists");
                    }
                    else if (csdl.KhachHangs.ToList().Exists(x => x.Email.Trim() == model.Email.Trim()))
                    {
                        ModelState.AddModelError("", "Email already exists");
                    }
                    else if (csdl.KhachHangs.ToList().Exists(x => x.DienThoai.Trim() == model.DienThoai.Trim()))
                    {
                        ModelState.AddModelError("", "Phone Numeber already exists");
                    }
                    else
                    {
                        KhachHang kh = new KhachHang();
                        kh.HoTen     = model.HoTen;
                        kh.GioiTinh  = model.GioiTinh.ToString();
                        kh.TaiKhoan  = model.TaiKhoan;
                        kh.MatKhau   = FileMaHoa.MD5Hash(model.MatKhau);
                        kh.NgaySinh  = model.NgaySinh;
                        kh.DiaChi    = model.DiaChi;
                        kh.DienThoai = model.DienThoai;
                        kh.Email     = model.Email;
                        kh.Status    = true;
                        csdl.KhachHangs.InsertOnSubmit(kh);
                        csdl.SubmitChanges();
                        ViewBag.Success = "Registered Successfully";
                        model           = new Register();
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "Registered Failed");
                }
            }

            return(View(model));
        }
 public ActionResult XuLyCreate(KhachHang kh)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var mahoa = FileMaHoa.MD5Hash(kh.MatKhau);
             kh.MatKhau = mahoa;
             csdl.KhachHangs.InsertOnSubmit(kh);
             csdl.SubmitChanges();
             SetAlert("Add Successful", "success");
             return(RedirectToAction("Index", "KhachHang"));
         }
         catch (Exception)
         {
             ModelState.AddModelError("", "Add Failded");
         }
     }
     return(View("Create"));
 }
 public ActionResult XuLyCreate(Manager nv)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var mahoa = FileMaHoa.MD5Hash(nv.Password);
             nv.Password = mahoa;
             csdl.Managers.InsertOnSubmit(nv);
             csdl.SubmitChanges();
             SetAlert("Add Successful", "success");
             return(RedirectToAction("Index", "Admin"));
         }
         catch (Exception)
         {
             ModelState.AddModelError("", "Add Failded");
         }
     }
     SetViewBag();
     return(View("Create"));
 }
 public ActionResult Edit(KhachHang kh)
 {
     try
     {
         var tmp = csdl.KhachHangs.ToList().SingleOrDefault(x => x.MaKH == kh.MaKH);
         tmp.NgaySinh = kh.NgaySinh;
         tmp.HoTen    = kh.HoTen;
         if (!string.IsNullOrEmpty(kh.MatKhau))
         {
             tmp.MatKhau = FileMaHoa.MD5Hash(kh.MatKhau);
         }
         tmp.DiaChi    = kh.DiaChi;
         tmp.DienThoai = kh.DienThoai;
         tmp.Email     = kh.Email;
         csdl.SubmitChanges();
         SetAlert("Update Successful", "success");
     }
     catch (Exception)
     {
         SetAlert("Update Failed", "error");
     }
     return(RedirectToAction("Index", "KhachHang"));
 }
 public ActionResult Edit(Manager nv)
 {
     try
     {
         var tmp = csdl.Managers.ToList().SingleOrDefault(x => x.ID == nv.ID);
         tmp.Name = nv.Name;
         if (!string.IsNullOrEmpty(nv.Password))
         {
             tmp.Password = FileMaHoa.MD5Hash(nv.Password);
         }
         tmp.Address = nv.Address;
         tmp.Phone   = nv.Phone;
         tmp.Email   = nv.Email;
         tmp.GroupID = nv.GroupID;
         csdl.SubmitChanges();
         SetAlert("Update Successful", "success");
     }
     catch (Exception)
     {
         SetAlert("Update Failed", "error");
     }
     SetViewBag(nv.GroupID);
     return(RedirectToAction("Index", "Admin"));
 }