Пример #1
0
 public void ThemNhanVien(NhanVienViewModel register)
 {
     User user = new User();
     user.TenDangNhap = register.TenDangNhap;
     user.TenDayDu = register.TenDayDu;
     user.MatKhau = BabyToys.Utilities.EditString.mahoa_md5(register.MatKhau);
     user.NgayTao = System.DateTime.Now;
     user.Email = register.Email;
     user.DiaChi = register.DiaChi;
     user.SoDienThoai = register.SoDienThoai;
     user.IdQuyen = register.IdQuyen;
     user.IsActive = true;
     db.Users.Add(user);
     db.SaveChanges();
 }
Пример #2
0
 public void SuaNhanVien(NhanVienViewModel u)
 {
     User user = new User();
     user.Id = u.Id;
     user.TenDangNhap = u.TenDangNhap;
     user.TenDayDu = u.TenDayDu;
     user.MatKhau = u.MatKhau;
     user.NgayTao = u.NgayTao;
     user.Email = u.Email;
     user.DiaChi = u.DiaChi;
     user.SoDienThoai = u.SoDienThoai;
     user.IdQuyen = u.IdQuyen;
     user.IsActive = u.IsActive;
     db.Entry(user).State = EntityState.Modified;
     db.SaveChanges();
 }
        public ActionResult DoiMatKhauUser()
        {
            User user = Session["admin"] as User;
            if(user!=null)
            {
                NhanVienViewModel userModel = new NhanVienViewModel()
                //userModel = user;
                {
                    Id = user.Id,
                    TenDangNhap = user.TenDangNhap,
                    TenDayDu = user.TenDayDu,
                    MatKhau = user.MatKhau,
                    XacNhanMatKhau = user.MatKhau,
                    Email = user.Email,
                    DiaChi = user.DiaChi,
                    SoDienThoai = user.SoDienThoai,
                    IsActive = user.IsActive,
                    NgayTao = user.NgayTao
                };
                //userModel = user as RegisterModel;
                ViewBag.IdQuyen = new SelectList(db.Quyens.ToList(), "IdQuyen", "TenQuyen", user.IdQuyen);
                return View(userModel);
            }

            return RedirectToAction("AdminLogin");
        }
 public ActionResult ThemUser(NhanVienViewModel register)
 {
     //if (ModelState.IsValid)
     //{
     //    BabyToys.DAL.RegisterDAL reg = new DAL.RegisterDAL();
     //    reg.ThemNhanVien(register);
     //    return RedirectToAction("Index");
     //}
     ViewBag.IdQuyen = new SelectList(db.Quyens.ToList(), "IdQuyen", "TenQuyen");
     return View(register);
 }
 public ActionResult SuaUser(NhanVienViewModel user)
 {
     //if (!Models.User.CurrentUser.Quyen.CoChucNang("sua_user"))
     //{
     //    return RedirectToAction("Error", "Admin");
     //}
     if (ModelState.IsValid)
     {
         var user_u = db.Users.SingleOrDefault(u => u.Id == user.Id);
         if (user_u.MatKhau != user.MatKhau)
         {
             user.MatKhau = Utilities.EditString.mahoa_md5(user.MatKhau);
         }
         BabyToys.DAL.RegisterDAL reg = new DAL.RegisterDAL();
         reg.SuaNhanVien(user);
         return RedirectToAction("Index");
     }
     ViewBag.IdQuyen = new SelectList(db.Quyens.ToList(), "IdQuyen", "TenQuyen", user.IdQuyen);
     return View(user);
 }
 public ActionResult SuaUser(int id = 0)
 {
     //if (!Models.User.CurrentUser.Quyen.CoChucNang("xem_user"))
     //{
     //    return RedirectToAction("Error", "Admin");
     //}
     User us = Session["admin"] as User;
     if (us.Id == id)
     {
         TempData["ThongBao"] = "Không thể sửa thông tin user trực tuyến";
         return RedirectToAction("Index");
     }
     var user = db.Users.SingleOrDefault(u => u.Id == id);
     NhanVienViewModel userModel = new NhanVienViewModel()
     //userModel = user;
     {
         Id = user.Id,
         TenDangNhap = user.TenDangNhap,
         TenDayDu = user.TenDayDu,
         MatKhau = user.MatKhau,
         XacNhanMatKhau = user.MatKhau,
         Email = user.Email,
         DiaChi = user.DiaChi,
         SoDienThoai = user.SoDienThoai,
         IsActive = user.IsActive,
         NgayTao=user.NgayTao
     };
     //userModel = user as RegisterModel;
     ViewBag.IdQuyen = new SelectList(db.Quyens.ToList(), "IdQuyen", "TenQuyen", user.IdQuyen);
     return View(userModel);
 }
 public ActionResult DoiMatKhauUser(NhanVienViewModel user)
 {
     if (ModelState.IsValid)
     {
         var user_u = db.Users.SingleOrDefault(u => u.Id == user.Id);
         if (user_u.MatKhau != user.MatKhau)
         {
             user.MatKhau = Utilities.EditString.mahoa_md5(user.MatKhau);
         }
         BabyToys.DAL.RegisterDAL reg = new DAL.RegisterDAL();
         reg.SuaNhanVien(user);
         return RedirectToAction("Index");
     }
     ViewBag.IdQuyen = new SelectList(db.Quyens.ToList(), "IdQuyen", "TenQuyen", user.IdQuyen);
     return View(user);
 }