示例#1
0
        /// <summary>
        /// 根据用户ID 获取用户可以访问的菜单
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <MenuInfo> GetMenusByUserId(string userId)
        {
            List <MenuInfo> menuInfo = new List <MenuInfo>();
            List <RoleInfo> roleInfo = new List <RoleInfo>();

            List <RoleMenuRelationship> roleMenuRelationship = new List <RoleMenuRelationship>();

            //获取用户拥有的角色
            List <UserRoleRelationship> itemList = BaseEntityFac.GetEntityByField <UserRoleRelationship>("UserInfoId", userId);

            foreach (var item in itemList)
            {
                if (roleInfo.Find(x => x.RoleInfoId == item.RoleInfoId) == null)
                {
                    //去掉用户拥有角色中的重复角色
                    RoleInfo ri = BaseEntityFac.GetEntityById <RoleInfo>(item.RoleInfoId);
                    if (ri != null)
                    {
                        roleInfo.Add(ri);
                    }
                }
            }

            foreach (var item in roleInfo)
            {
                //获取角色可以访问的菜单
                List <RoleMenuRelationship> itemRMRList = BaseEntityFac.GetEntityByField <RoleMenuRelationship>("RoleInfoId", item.RoleInfoId);

                foreach (var itemMenu in itemRMRList)
                {
                    if (roleMenuRelationship.Find(x => x.MenuInfoId == itemMenu.MenuInfoId) == null)
                    {
                        MenuInfo mi = BaseEntityFac.GetEntityById <MenuInfo>(itemMenu.MenuInfoId);
                        if (mi != null)
                        {
                            menuInfo.Add(mi);
                        }
                    }
                }
            }


            if (menuInfo != null && menuInfo.Count > 0)
            {
                menuInfo = menuInfo.OrderBy(x => x.OrderNo).ToList();
            }


            return(menuInfo);
        }
示例#2
0
        //UserRoleRelationshipData _Data = new UserRoleRelationshipData();

        #region 业务数据查询
        /// <summary>
        /// 根据实体类 主键 查询实体信息
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public UserRoleRelationship GetEntityById(string id)
        {
            return(BaseEntityFac.GetEntityById <UserRoleRelationship>(id));
        }