コード例 #1
0
ファイル: UserDao.cs プロジェクト: hiennx1991/OnlineShopping
        public long InsertForFacebook(User entity)
        {
            var user = db.Users.SingleOrDefault(x => x.Username == entity.Username);

            if(user == null)
            {
                db.Users.Add(entity);
                db.SaveChanges();
                return entity.ID;
            }
            else
            {
                return user.ID;
            }
        }
コード例 #2
0
        public ActionResult Create(Model.EF.User user)
        {
            var dao = new UserDao();

            var encrypt = Encrypt.MD5Hash(user.password);

            user.password = encrypt;

            int id = dao.InsetUser(user);

            if (id > 0)
            {
                return(RedirectToAction("Index", "User"));
            }
            else
            {
                ModelState.AddModelError("", "Them nguoi dung khong thanh cong");
            }
            return(View("Index", "Home"));
        }
コード例 #3
0
 public ActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         var dao = new UserDao();
         var encryptedMD5Pas = Encryptor.MD5Hash(user.Password);
         user.Password = encryptedMD5Pas;
         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;
                }

                var result = dao.Update(user);
                if (result)
                {
                    SetAlert("Sửa 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
ファイル: UserDao.cs プロジェクト: hiennx1991/OnlineShopping
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return entity.ID;
 }
コード例 #6
0
ファイル: UserDao.cs プロジェクト: hiennx1991/OnlineShopping
 public bool Update(User entity)
 {
     try
     {
         var user = db.Users.Find(entity.ID);
         user.Name = entity.Name;
         if (!string.IsNullOrEmpty(entity.Password))
         {
             user.Password = entity.Password;
         }
         user.Address = entity.Address;
         user.Email = entity.Email;
         user.ModifiedBy = entity.ModifiedBy;
         user.ModifiedDate = DateTime.Now;
         db.SaveChanges();
         return true;
     }catch(Exception ex)
     {
         return false;
     }
 }