Beispiel #1
0
        //dto转换
        private static void DepartmentDto(IEnumerable <Esmart_Sys_Departments> departments, List <DepartmentResponse> result, bool withUser)
        {
            foreach (var item in departments)
            {
                var dto = new DepartmentResponse
                {
                    DeparentId = item.DeparentId,
                    Name       = item.Name,
                    ParentId   = item.ParentId
                };

                result.Add(dto);

                if (item.Children == null || item.Children.Count == 0)
                {
                    dto.Children = new List <DepartmentResponse>();
                }
                else
                {
                    dto.Children = new List <DepartmentResponse>(item.Children.Count);
                    DepartmentDto(item.Children, dto.Children, withUser);
                }

                if (withUser)
                {
                    var users = DepartmentUserDbAction.GetUsersInDepartment(item.DeparentId, false);
                    dto.Users = users.Select(n => new DepartmentUserResponse
                    {
                        UserID   = n.UserID,
                        UserName = n.TrueName
                    }).ToList();
                }
            }
        }
Beispiel #2
0
        public SoaDataPageResponse <UsersView> GetUsersByDepartList(SoaDataPage <UserSearchModel> filter)
        {
            SoaDataPageResponse <UsersView> response;

            if (filter.Where.DeapartmentId != 0)
            {
                response = DepartmentDbAction.GetUsersByDepartList(filter);
            }
            else
            {
                IQueryable <UsersView> query;

                if (CommonAction.IsSysAdmin(filter.Where.UserId))
                {
                    query = DepartmentUserDbAction.GetAllUsers(true).AsQueryable();
                }
                else
                {
                    var userList = new List <UsersView>(100);

                    var departments = DepartmentDbAction.GetDepartments(filter.Where.UserId);

                    foreach (var department in departments)
                    {
                        var users = DepartmentUserDbAction.GetUsersInDepartment(department.DeparentId, true);
                        userList.AddRange(users);
                    }

                    query = userList.AsQueryable();
                }

                if (!string.IsNullOrWhiteSpace(filter.Where.TrueName))
                {
                    query = query.Where(n => n.TrueName != null && n.TrueName.Contains(filter.Where.TrueName));
                }

                if (!string.IsNullOrWhiteSpace(filter.Where.Ename))
                {
                    query = query.Where(n => n.Ename != null && n.Ename.Contains(filter.Where.Ename));
                }

                if (!string.IsNullOrWhiteSpace(filter.Where.WorkNo))
                {
                    query = query.Where(n => n.WorkNo != null && n.WorkNo.Contains(filter.Where.WorkNo));
                }

                response = new SoaDataPageResponse <UsersView> {
                    Count = query.Count()
                };

                query = !string.IsNullOrWhiteSpace(filter.OrderBy) ? query.SortBy(filter.OrderBy + " " + filter.SortCol) : query.OrderByDescending(n => n.CreateTime);

                response.Body = query.Skip((filter.PageIndex - 1) * filter.PageSize).Take(filter.PageSize).ToList();
            }

            foreach (var user in response.Body)
            {
                user.RoleNames = string.Join(",", UserRolesDbAction.GetUserRoleNames(user.UserID));
            }

            return(response);
        }