예제 #1
0
 public String SetUsersOutGroup(string[] arrChecked, string RoleID)
 {
     try
     {
         string[]         arrUserID      = arrChecked;
         int              intRoleID      = Convert.ToInt32(RoleID);
         CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO();
         if (arrUserID != null && arrUserID.Length > 0)
         {
             string listUserID = "(";
             for (int i = 0; i < arrUserID.Length; i++)
             {
                 listUserID += arrUserID[i].ToString() + ",";
             }
             listUserID  = listUserID.Substring(0, listUserID.Length - 1);
             listUserID += ")";
             if (objUserRoleDAO.RemoveUsersOutGroup(intRoleID, listUserID))
             {
                 return("true");
             }
         }
         return("false");
     }
     catch (Exception ex)
     {
         //SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return("false");
     }
 }
예제 #2
0
 public String SetUsersInGroup(string[] arrChecked, string RoleID)
 {
     try
     {
         string[]         arrUserID      = arrChecked;
         int              intRoleID      = Convert.ToInt32(RoleID);
         int              intUserID      = 0;
         CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO();
         if (arrUserID != null && arrUserID.Length > 0)
         {
             for (int i = 0; i < arrUserID.Length; i++)
             {
                 intUserID = Convert.ToInt32(arrUserID[i].ToString());
                 objUserRoleDAO.Insert(intUserID, intRoleID);
             }
             return("true");
         }
         return("false");
     }
     catch (Exception ex)
     {
         //SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return("false");
     }
 }
예제 #3
0
 public ActionResult Edit(int id)
 {
     try
     {
         CSF_Users_DAO objUsersDAO = new CSF_Users_DAO();
         var           user        = objUsersDAO.GetUserByID(id);
         if (user == null)
         {
             return(RedirectToAction("Index", "QT_Users"));
         }
         CSF_Roles_DAO objRolesDAO = new CSF_Roles_DAO();
         var           roles       = objRolesDAO.GetAll();
         TempData["Roles"] = roles.ToList();
         TempData.Keep("Roles");
         //Hiển thị Role đã có của User
         CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO();
         List <CSF_UserRole_GetByUser_Result> userRole = objUserRoleDAO.GetListRoleByUserID(id);
         TempData["userRole"] = userRole;
         TempData.Keep("userRole");
         return(View(user));
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }
예제 #4
0
        public ActionResult Create(FormCollection fc, CSF_Users user)
        {
            try
            {
                ViewBag.isReload    = 1;
                ViewBag.DonViSelect = Request.Form["MaDonVi"];

                //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home");
                if (ModelState.IsValid)
                {
                    CSF_Users_DAO objUsersDAO = new CSF_Users_DAO();
                    //Kiểm tra trùng tên tài khoản
                    if (objUsersDAO.CheckUserName(user.UserName.Trim()))
                    {
                        ModelState.AddModelError("", "Tên người dùng đã tồn tại!");
                        TempData.Keep("Roles");
                        return(View());
                    }

                    int ReturnUserID = objUsersDAO.Insert(user);
                    if (ReturnUserID > 0)
                    {
                        SetAlert("Thêm người dùng thành công", AlertType.Success);
                        //Thêm người dùng vào nhóm
                        CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO();
                        if (fc["chkRole_"] != null)
                        {
                            string[] arrRoleCheckBox = fc["chkRole_"].Split(',');
                            int      intRoleID       = 0;
                            for (int i = 0; i < arrRoleCheckBox.Length; i++)
                            {
                                intRoleID = Convert.ToInt32(arrRoleCheckBox[i].ToString());
                                objUserRoleDAO.Insert(user.ID, intRoleID);
                            }
                        }
                        return(RedirectToAction("Index", "QT_Users"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm người dùng không thành công");
                    }
                    return(View("Index"));
                }
                TempData.Keep("Roles");
                return(View());
            }
            catch (Exception ex)
            {
                SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
                Logs.WriteLog(ex);
                return(View());
            }
        }
예제 #5
0
 public ActionResult Edit(FormCollection fc, CSF_Users user)
 {
     try
     {
         //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home");
         //Xóa nhóm hiện tại của người dùng
         CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO();
         objUserRoleDAO.DelRoleByUserID(user.ID);
         CSF_Users_DAO objUsersDAO = new CSF_Users_DAO();
         if (objUsersDAO.Update(user))
         {
             if (fc["chkRole_"] != null)
             {
                 string[] arrRoleCheckBox = fc["chkRole_"].Split(',');
                 int      intRoleID       = 0;
                 for (int i = 0; i < arrRoleCheckBox.Length; i++)
                 {
                     intRoleID = Convert.ToInt32(arrRoleCheckBox[i].ToString());
                     objUserRoleDAO.Insert(user.ID, intRoleID);
                 }
             }
             SetAlert("Cập nhật người dùng thành công", AlertType.Success);
             return(RedirectToAction("Index", "QT_Users"));
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật người dùng không thành công");
         }
         return(View("Index"));
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }