public int EditItem(int id, USER User)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             USER U = db.USERS.Find(id);
             if (User.PASSWORD != null && !User.PASSWORD.Equals(""))
             {
                 U.PASSWORD = MyEndCode.mahoa(User.PASSWORD);
             }
             U.FULLNAME        = User.FULLNAME;
             U.ACTIVE          = User.ACTIVE;
             U.PICTURE         = User.PICTURE;
             U.PHONE           = User.PHONE;
             U.ADDRESS         = User.ADDRESS;
             U.ID_ROLE         = User.ID_ROLE;
             db.Entry(U).State = EntityState.Modified;
             int i = db.SaveChanges();
             transaction.Commit();
             return(i);
         }
         catch
         {
             transaction.Rollback();
             return(0);
         }
     }
 }
Exemple #2
0
        public ActionResult Index(LOGIN Login)
        {
            if (!ModelState.IsValid)
            {
                return(View(Login));
            }
            if (Membership.ValidateUser(Login.email, MyEndCode.mahoa(Login.password)))
            {
                var user = (CustomMemberShipUser)Membership.GetUser(Login.email, false);
                if (!user.ACTIVE)
                {
                    ViewBag.message = "Tài khoản chưa được kích hoạt. Vui lòng liên hệ admin để được kích hoạt";
                }
                else
                {
                    if (user != null)
                    {
                        CustomSerializeModel userModel = new CustomSerializeModel()
                        {
                            ID       = user.ID,
                            EMAIL    = user.EMAIL,
                            FULLNAME = user.FULLNAME,
                            ACTIVE   = user.ACTIVE,
                            PICTURE  = user.PICTURE,
                            PHONE    = user.PHONE,
                            ADDRESS  = user.ADDRESS,
                            ROLE     = user.ROLE
                        };

                        string userData = JsonConvert.SerializeObject(userModel);
                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket
                                                               (
                            1, Login.email, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData
                                                               );

                        string     enTicket = FormsAuthentication.Encrypt(authTicket);
                        HttpCookie faCookie = new HttpCookie("Cookie1", enTicket);
                        Response.Cookies.Add(faCookie);
                    }
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                ViewBag.message = "Email hoặc mật khẩu không đúng";
            }
            return(View(Login));
        }
 public int AddItem(USER User)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             User.PASSWORD = MyEndCode.mahoa(User.PASSWORD);
             db.USERS.Add(User);
             int i = db.SaveChanges();
             transaction.Commit();
             return(i);
         }
         catch
         {
             transaction.Rollback();
             return(0);
         }
     }
 }