예제 #1
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao = new UserDao();
                var result = dao.Login(model.UserName, Encryptor.MD5Hash(model.Password));
                if (result == 1)
                {
                    var user = dao.GetById(model.UserName);
                    var userSession = new UserLogin();
                    userSession.UserName = user.UserName;
                    userSession.UserID = user.ID;

                    Session.Add(CommonConstants.USER_SESSION, userSession);
                    return RedirectToAction("Index", "Home");
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại.");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "Tài khoản đang bị khóa.");
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "Mật khẩu không đúng.");
                }
                else
                {
                    ModelState.AddModelError("", "Đăng nhập không đúng.");
                }
            }
            return View("Index");
        }
예제 #2
0
 public JsonResult ChangeStatus(long id)
 {
     var result = new UserDao().ChangeStatus(id);
     return Json(new
     {
         status = result
     });
 }
예제 #3
0
 public ActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         var dao = new UserDao();
         user.Password = Encryptor.MD5Hash(user.Password);
         long id = dao.Insert(user);
         if (id > 0)
         {
             SetAlert("Thêm user thành công", "success");
             return RedirectToAction("Index", "User");
         }
         else
         {
             ModelState.AddModelError("", "Thêm user không thành công");
         }
     }
     return View("Index");
 }
예제 #4
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                var dao = new UserDao();
                if(!string.IsNullOrEmpty(user.Password))
                {
                    var encryptedMd5Pas = Encryptor.MD5Hash(user.Password);
                    user.Password = encryptedMd5Pas;
                }

                if (dao.Update(user))
                {
                    SetAlert("Cập nhật user thành công", "success");
                    return RedirectToAction("Index", "User");
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật user không thành công");
                }
            }
            return View("Index");
        }
예제 #5
0
 // GET: Admin/User
 public ActionResult Index(string searchString, int page = 1, int pageSize = 10)
 {
     var dao = new UserDao();
     var model = dao.ListAllPaging(searchString, page, pageSize);
     ViewBag.SearchString = searchString;
     return View(model);
 }
예제 #6
0
 public ActionResult Edit(int id)
 {
     var user = new UserDao().ViewDetail(id);
     return View(user);
 }
예제 #7
0
 public ActionResult Delete(int id)
 {
     var user = new UserDao();
     user.Delete(id);
     return RedirectToAction("Index");
 }