Esempio n. 1
0
        public ActionResult Update(int id)
        {
            //co quyen moi duoc update
            if (!CheckRole(_httpContext, int.Parse(Roles.Phan_Quyen_Update)))
            {
                return(View("_NoAuthor"));
            }

            Account298  nhanVien = _account298Repository.GetById(id);
            IList <int> ids      = !string.IsNullOrEmpty(nhanVien.Roles)
                                        ? nhanVien.Roles.Split(',').Select(o => Convert.ToInt32(o)).ToList()
                                        : new List <int>();
            IList <RoleList> roles = Roles.GetRoles();

            IList <PhanQuyenModel.SetQuyen> phanQuyenModels = new List <PhanQuyenModel.SetQuyen>();

            ViewData["TenNhanVien"] = nhanVien.Fullname;
            foreach (var r in roles)
            {
                phanQuyenModels.Add(new PhanQuyenModel.SetQuyen()
                {
                    NhanVienId = id,
                    IdQuyen    = r.Id,
                    Selected   = ids.Contains(r.Id),
                    TenQuyen   = r.Name
                });
            }
            return(View(phanQuyenModels));
        }
Esempio n. 2
0
        public JsonResult save(PhanQuyenModel.SaveModel form)
        {
            Account298  nhanVien = _account298Repository.GetById(form.idNhanVien);
            IList <int> ids      = !string.IsNullOrEmpty(nhanVien.Roles)
                                       ? nhanVien.Roles.Split(',').Select(o => Convert.ToInt32(o)).ToList()
                                       : new List <int>();

            if (form.Checked)
            {
                if (!ids.Any(o => o == form.IdQuyen))
                {
                    ids.Add(form.IdQuyen);
                }
            }
            else
            {
                ids.Remove(form.IdQuyen);
            }
            nhanVien.Roles = string.Join(",", ids);
            _account298Repository.Update(nhanVien);
            _unitOfWork.Commit();

            formAuthentication.SetAuthCookie(this.HttpContext,
                                             UserAuthenticationTicketBuilder.CreateAuthenticationTicket(
                                                 nhanVien));

            return(Json(new { ok = true, JsonRequestBehavior.AllowGet }));
        }
Esempio n. 3
0
 public ActionResult Login(DangNhapModel form, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         Account298 user = _account298Repository.Get(o => o.Username.Equals(form.Username));
         if (user != null)
         {
             if (ValidatePassword(user, form.Password))
             {
                 //dang nhap thanh cong
                 //  SetCookieLogin(this.Request.RequestContext, form.Username);
                 formAuthentication.SetAuthCookie(this.HttpContext, UserAuthenticationTicketBuilder.CreateAuthenticationTicket(user));
                 return(RedirectToAction("ViewDanhMuc", "DanhMucSanPham"));
             }
             else
             {
                 ViewData["Message"] = "Mật Khẩu Sai";
                 return(View("Index", form));
             }
         }
         else
         {
             ViewData["Message"] = "Tên đăng nhập không tồn tại";
             return(View("Index", form));
         }
     }
     else
     {
         return(View("Index", form));
     }
 }
Esempio n. 4
0
        public ActionResult GetUser()
        {
            string     username = User.Identity.Name;
            Account298 ac       = null;

            if (!string.IsNullOrEmpty(username))
            {
                ac = _account298Repository.Get(o => o.Username.Equals(username));
                return(View("User", ac));
            }
            return(View("User", ac));
        }
        public ActionResult SaveEdit(Account298 model)
        {
            Account298 ac = _account298Repository.GetById(model.id_);

            ac.id_        = model.id_;
            ac.Email      = model.Email;
            ac.Fullname   = model.Fullname;
            ac.Password   = Md5Encrypt.Md5EncryptPassword(model.Password);
            ac.Permission = model.Permission;
            ac.Show       = model.Show;
            ac.Username   = model.Username;
            _account298Repository.Update(ac);
            _unitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
        public JsonResult saveAll(PhanQuyenModel.SaveModel form)
        {
            Account298       nhanVien = _account298Repository.GetById(form.idNhanVien);
            IList <RoleList> roles    = Roles.GetRoles();

            IList <int> ids = new List <int>();

            if (form.Checked)
            {
                ids = roles.Select(o => o.Id).ToList();
            }

            nhanVien.Roles = string.Join(",", ids);
            _account298Repository.Update(nhanVien);
            _unitOfWork.Commit();

            formAuthentication.SetAuthCookie(this.HttpContext,
                                             UserAuthenticationTicketBuilder.CreateAuthenticationTicket(
                                                 nhanVien));
            return(Json(new { ok = true, JsonRequestBehavior.AllowGet }));
        }
 public ActionResult AddNew(ThemAccountModel model)
 {
     if (ModelState.IsValid)
     {
         Account298 ac = new Account298()
         {
             Email      = model.Email,
             Username   = model.Username,
             Fullname   = model.Fullname,
             Show       = model.Show,
             Permission = model.Permission,
             Password   = Md5Encrypt.Md5EncryptPassword(model.Password),
         };
         _account298Repository.Add(ac);
         _unitOfWork.Commit();
     }
     else
     {
         return(View("Create", model));
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult DoiMatKhau(Account298 model)
 {
     //load session dang luu roi doi mat khau cua thang do luon
     return(View("Doimatkhau"));
 }
Esempio n. 9
0
        private bool ValidatePassword(Account298 user, string password)
        {
            var encoded = Md5Encrypt.Md5EncryptPassword(password);

            return(user.Password.Equals(encoded));
        }