Example #1
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);
        }
Example #2
0
        /// <summary>
        /// 给用户赋予角色
        /// </summary>
        /// <param name="rolelistIds">多个选中的角色id</param>
        /// <param name="keyValue">用户id</param>
        public void roleAuthority(string rolelistIds, int keyValue)
        {
            user          u                  = this.getEntityById(keyValue);
            roleEx        re                 = new roleEx();
            IuserRoleEx   userRoleEx         = new userRoleEx();
            List <role>   currentUserAllRole = re.getUserRoles(u.username);
            List <string> currentUserRoleIds = new List <string>();

            foreach (var item in currentUserAllRole)
            {
                currentUserRoleIds.Add(item.id.ToString());
            }
            if (!string.IsNullOrEmpty(rolelistIds))
            {
                string[]      ids             = rolelistIds.Split(',');
                List <string> roleIdsList     = ids.ToList();
                var           interselectlist = roleIdsList.Intersect(currentUserRoleIds).ToList(); //对数据库中角色id和当前用户的角色id做交集
                var           exceptList      = currentUserRoleIds.Except(roleIdsList).ToList();    //做差集,选出当前用户数据库中有但没有传入的id。
                if (exceptList != null)
                {
                    foreach (var item in exceptList)
                    {
                        //userRoleEx.delete(Convert.ToInt32(item));
                        // userRoleEx.deleteEntity(Convert.ToInt32(item));
                        userRoleEx.deleteUerRole(keyValue, Convert.ToInt32(item));
                    }
                }
                var exceptList1 = roleIdsList.Except(currentUserRoleIds).ToList();//做差集,选出传入的角色id有但数据库中该用户没有的角色id
                if (exceptList1 != null)
                {
                    foreach (var item in exceptList1)
                    {
                        userRoleEx.insertUserRole(keyValue, Convert.ToInt32(item));
                    }
                }
            }
        }