Exemplo n.º 1
0
        public List <UserLiteDto> GetGroupUsersByLoginUserID(int userId)
        {
            List <UserLiteDto> lstResult = null;

            try
            {
                SoaDataPage <UserSearchModel> filter = new SoaDataPage <UserSearchModel>();;
                CommonFunction.InitializeSoaDataPage(filter);
                filter.Where.UserId = userId;
                filter.PageIndex    = 1;
                filter.PageSize     = 100000000;
                var result = new Esmart.Permission.Application.DeparentManager.DepartmentManager().GetUsersByDepartList(filter);
                if (result != null && !CommonAction.IsSysAdmin(userId))
                {
                    List <UsersView> lstDepart = DepartmentUserDbAction.GetGroupsByUserId(userId);
                    lstResult = result.Body.Where(w => lstDepart.Find(f => f.UserID == w.UserID) != null).ToList().ConvertAll(c => new UserLiteDto {
                        UserID = c.UserID, TrueName = c.TrueName, WorkNo = c.WorkNo, Email = c.Email, Ename = c.Ename, Sex = c.Sex
                    });
                }
                else
                {
                    lstResult = result.Body.ToList().ConvertAll(c => new UserLiteDto {
                        UserID = c.UserID, TrueName = c.TrueName, WorkNo = c.WorkNo, Email = c.Email, Ename = c.Ename, Sex = c.Sex
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(lstResult);
        }
Exemplo n.º 2
0
        public List <UserLiteDto> GetGroupUsersByFunctionKey(string functionKey, int userId, int menuId, int appId = 0)
        {
            var engine = PermissionDb.CreateEngine();

            // var funcId = engine.Esmart_Sys_Functions.Where(n => n.FunctionKey == functionKey && n.).Select(n => n.FunctionId).FirstOrDefault();

            //if (funcId < 1) return new List<UserLiteDto>(0);

            var query1 = (from user in engine.Esmart_Sys_Users
                          join userRole in engine.Esmart_Sys_User_Roles on user.UserID equals userRole.UserId
                          join roleFunc in engine.Esmart_Sys_Role_Navigation_Function on userRole.RoleId equals roleFunc.RoleId
                          join func in engine.Esmart_Sys_Functions on roleFunc.FunctionId equals func.FunctionId
                          where user.Isleave != 1 && user.IsDelete != 1 && func.FunctionKey == functionKey && (menuId > 0 ? roleFunc.NavigationId == menuId : true)
                          select new UserLiteDto
            {
                UserID = user.UserID,
                Ename = user.Ename,
                TrueName = user.TrueName,
                WorkNo = user.WorkNo
            }).Union(
                from user in engine.Esmart_Sys_Users
                join userFunc in engine.Esmart_Sys_User_Navigation_Function on user.UserID equals userFunc.UserId
                join func in engine.Esmart_Sys_Functions on userFunc.FunctionId equals func.FunctionId
                where user.Isleave != 1 && user.IsDelete != 1 && func.FunctionKey == functionKey && (menuId > 0 ? userFunc.NavigationId == menuId : true)
                select new UserLiteDto
            {
                UserID   = user.UserID,
                Ename    = user.Ename,
                TrueName = user.TrueName,
                WorkNo   = user.WorkNo
            });

            var groupUsers = DepartmentUserDbAction.GetGroupsByUserId(userId);
            var filterto   = groupUsers.ConvertAll(c => c.UserID);
            List <UserLiteDto> lstUsers = CommonAction.IsSysAdmin(userId)?query1.ToList(): query1.Where(w => filterto.Contains(w.UserID)).ToList();
            var allUsers = lstUsers.Where((x, i) => lstUsers.FindIndex(f => f.UserID == x.UserID) == i).ToList();

            return(allUsers);
        }