예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="trueName"></param>
        /// <param name="deptName"></param>
        /// <param name="roleId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public List <cmsUser> GetUsersByFilter(string loginName, string trueName, string deptName, int roleId, int pageIndex, int pageSize, ref int recordCount)
        {
            UserRoleService urs = UserRoleService.GetInstance();

            WhereClipBuilder wcb = new WhereClipBuilder();

            if (!string.IsNullOrEmpty(loginName))
            {
                wcb.And(cmsUser._.UName.Contain(loginName.Trim()));
            }
            if (!string.IsNullOrEmpty(trueName))
            {
                wcb.And(cmsUser._.Name.Contain(trueName.Trim()));
            }
            if (!string.IsNullOrEmpty(deptName.Trim()))
            {
                wcb.And(cmsUser._.DeptName.Contain(deptName.Trim()));
            }
            if (roleId > 0)
            {
                FromSection fs = DBSession.CurrentSession.From <cmsUserRole>()
                                 .Select(cmsUserRole._.UserId)
                                 .Where(cmsUserRole._.RoleId == roleId);

                wcb.And(cmsUser._.Id.SubQueryIn(fs));
            }
            return(GetList(wcb.ToWhereClip(), cmsUser._.UName.Asc, pageIndex, pageSize, ref recordCount));
        }
예제 #2
0
 static UserRoleService()
 {
     if (instance == null)
     {
         lock (lockObj)
         {
             instance = new UserRoleService();
         }
     }
 }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <cmsUserPurview> GetUserAllPurview(long userId)
        {
            List <cmsUserPurview> all = new List <cmsUserPurview>();

            var ups = GetList(cmsUserPurview._.UserId == userId, null);

            all.AddRange(ups);

            // 获取用户所属的全部角色
            List <cmsUserRole> userroles = UserRoleService.GetInstance().GetList(cmsUserRole._.UserId == userId, null);

            if (userroles.Count > 0)
            {
                long[] roles = new long[userroles.Count];
                for (int i = 0; i < userroles.Count; i++)
                {
                    roles[i] = userroles[i].RoleId.Value;
                }
                // 获取全部角色所拥有的权限
                List <cmsRolePurview> rps = RolePurviewService.GetInstance().GetList(cmsRolePurview._.RoleId.SelectIn(roles), null);
                foreach (var p in rps)
                {
                    // 去重
                    if (all.Exists(x => x.Type == p.Type && x.NodeCode == p.NodeCode))
                    {
                        continue;
                    }

                    all.Add(new cmsUserPurview()
                    {
                        Id       = 0,
                        UserId   = userId,
                        NodeCode = p.NodeCode,
                        Type     = p.Type
                    });
                }
            }
            return(all);
        }