Exemplo n.º 1
0
        public ActionResult Edit(User user)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index"));
            }
            var data = new UserData();

            if (!string.IsNullOrEmpty(user.Password))
            {
                var md5Encryptedpwd = Encryptor.Md5Hash(user.Password);
                user.Password = md5Encryptedpwd;
            }

            var id = data.UpdateUser(user);

            if (id)
            {
                SetAlert("Update User Success", "success");
                return(RedirectToAction("Index", "User"));
            }
            ModelState.AddModelError("", "Cannot Edit user");

            return(View("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                var data            = new UserData();
                var md5Encryptedpwd = Encryptor.Md5Hash(user.Password);
                user.Password    = md5Encryptedpwd;
                user.CreatedDate = DateTime.Now;
                var id = data.Insert(user);
                if (id > 0)
                {
                    SetAlert("Add User Success", "success");
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    SetAlert("Add User Failed", "error");
                    ModelState.AddModelError("", "Cannot Add user");
                }
            }

            return(View("Create"));
        }