Ejemplo n.º 1
0
 public int Delete(int id)
 {
     try
     {
         var user = db.Accounts.Find(id);
         db.Accounts.Remove(user);
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Ejemplo n.º 2
0
        public ActionResult ChangePass(ChangeModel model)
        {
            Account acc = new Account();

            if (ModelState.IsValid)
            {
                var user = db.Accounts.SingleOrDefault(a => a.Username == model.Username);
                if (user != null)
                {
                    if (user.Password == model.Password)   //nếu đúng pass của tài khoản mới cập nhập
                    {
                        user.Password = model.NewPassword; //Hàm cập nhập mật khẩu
                        db.SaveChanges();
                        TempData["Success"] = "Đổi mật khẩu thành công";
                        return(RedirectToAction("Index", "Account"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Mật khẩu cũ không dúng, vui lòng nhập lại!");
                        return(View());
                    }
                }
            }
            ModelState.AddModelError("", "Đổi mật khẩu thất bại");
            return(View());
        }