コード例 #1
0
        public ActionResult HeThongChangePassSieuThi(int?id)
        {
            if (id == default(int) || id == 0)
            {
                return(RedirectToRoute("AdminPanel"));
            }
            SieuThi _sieuthi = db.SieuThis.Find(id);

            if (_sieuthi == null)
            {
                return(RedirectToRoute("AdminPanel"));
            }
            var getSieuthi = new ChangePasswordSieuthiViewModel()
            {
                SieuthiId = _sieuthi.SieuThiId
            };

            ViewBag.TenSieuThi = _sieuthi.TenSieuThi;
            return(View(getSieuthi));
        }
コード例 #2
0
        public ActionResult HeThongChangePassSieuThi(ChangePasswordSieuthiViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (new UserManager().CheckPassUserSieuthi(User.Identity.Name, model.OldPassword))
            {
                var _sieuthi = db.SieuThis.Find(model.SieuthiId);
                if (_sieuthi != null)
                {
                    _sieuthi.pass = model.NewPassword != null?Helpers.Config.Encrypt(model.NewPassword) : null;

                    db.Entry(_sieuthi).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["Updated"] = "Cập nhật mật khẩu mới thành công!";
                }
                return(RedirectToRoute("HethongChangePassST", new { id = model.SieuthiId }));
            }
            ModelState.AddModelError("", "Mật khẩu hiện tại không đúng.");
            return(View());
        }