Exemplo n.º 1
0
        /// <summary>
        /// 根据用户id删除对应的用户及该用户对应的分组和角色
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        public bool deleteuserRG(int id)
        {
            userRoleEx   ure          = new userRoleEx();
            List <role>  curroleList  = ure.getRoleList(id);
            userGroupEx  uge          = new userGroupEx();
            List <group> curgroupList = uge.getGroupList(id);
            user         u            = getUser(id);
            bool         uflag        = db.Delete <user>(u);

            if (curroleList.Count == 0 && curgroupList.Count == 0)
            {
                return(uflag);
            }
            else
            {
                bool urflag = true;
                bool ugflag = true;
                foreach (var item in curroleList)
                {
                    user_role ur = ure.getUserRole(id, item.id);
                    urflag = db.Delete <user_role>(ur);
                }
                foreach (var item in curgroupList)
                {
                    user_group ug = uge.getUserGroup(id, item.id);
                    ugflag = db.Delete <user_group>(ug);
                }
                return(uflag & urflag & ugflag);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取用户及角色和所属分组
        /// </summary>
        /// <returns></returns>
        public DataTable getUserRoleGroup(string keyValue)
        {
            var       r  = db.Queryable <user>().ToList();
            DataTable dt = db.Queryable <user>().ToDataTable();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                userRoleEx  ure = new userRoleEx();
                userGroupEx uge = new userGroupEx();
                dt.Rows[i]["rolelist"]  = ure.getRoleName(Convert.ToInt32(dt.Rows[i]["id"]));
                dt.Rows[i]["grouplist"] = uge.getGroupName(Convert.ToInt32(dt.Rows[i]["id"]));
            }
            return(dt);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取用户表的分页并显示用户角色及分组
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize">页面的数据总数</param>
        /// <param name="searchStr">搜索的字段</param>
        /// <returns></returns>
        public List <user> getPaginationUserList(int pageIndex, int pageSize, Dictionary <string, object> searchStr)
        {
            userRoleEx  ure        = new userRoleEx();
            userGroupEx uge        = new userGroupEx();
            List <user> entitylist = new List <user>();
            var         entitydata = getEntityList(searchStr);
            var         pagerfirst = (pageIndex - 1) * pageSize;

            entitylist = entitydata.Skip(pagerfirst).Take(pageSize).ToList();
            foreach (user us in entitylist)
            {
                us.rolelist  = ure.getRoleName(us.id);
                us.grouplist = uge.getGroupName(us.id);
            }
            return(entitylist);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 给用户分配分组
        /// </summary>
        /// <param name="grouplistIds">分组id</param>
        /// <param name="keyValue">用户id</param>
        public void groupAuthority(string grouplistIds, int keyValue)
        {
            user          u                   = this.getEntityById(keyValue);
            IuserGroupEx  userGroupEx         = new userGroupEx();
            userGroupEx   uge                 = new dal.userGroupEx();
            List <group>  currentUserGroup    = uge.getGroup(u.username);
            List <string> currentUserGroupIds = new List <string>();

            foreach (var item in currentUserGroup)
            {
                currentUserGroupIds.Add(item.id.ToString());
            }
            if (!string.IsNullOrEmpty(grouplistIds))
            {
                string[]      ids             = grouplistIds.Split(',');
                List <string> groupIds        = ids.ToList();
                var           interselectList = groupIds.Intersect(currentUserGroupIds).ToList(); //对数据库中分组id和当前用户的分组id做交集
                var           exceptList      = currentUserGroupIds.Except(groupIds).ToList();    ////做差集,选出当前用户数据库中有但没有传入的分组id。
                if (exceptList != null)
                {
                    foreach (var item in exceptList)
                    {
                        userGroupEx.deleteUserGroup(keyValue, Convert.ToInt32(item));
                    }
                }
                var exceptList1 = groupIds.Except(currentUserGroupIds).ToList();//做差集,选出传入的分组id中有但数据库中该用户没有的分组id
                if (exceptList1 != null)
                {
                    foreach (var item in exceptList1)
                    {
                        userGroupEx.insertUserGroup(keyValue, Convert.ToInt32(item));
                    }
                }
            }
            string groupnameofus = uge.getGroupName(u.id);

            u.grouplist = groupnameofus;
            this.update(u);
        }