//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(); } } }
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); }
public int CreateUserWithDepartmentId(Esmart_Sys_Users user, int departMentId) { if (user.UserID == 0) { user.CreateTime = DateTime.Now; UserManagerDb.Add(user); } Esmart_Sys_Department_User departUser = new Esmart_Sys_Department_User { DeparentId = departMentId, UserId = user.UserID, CreateTime = DateTime.Now, CreateId = user.CreateId }; DepartmentUserDbAction.Add(departUser); CommonAction.ClearCache(user.UserID); return(user.UserID); }
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); }
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); }
public bool DeleteUser(int pm_UserID, int departMentId) { DepartmentUserDbAction.DelDepartmentRelation(pm_UserID, departMentId); return(true); }
public bool ChangeDepartmentOfUser(List <int> userIds, int newDepartmentId, int createId) { DepartmentUserDbAction.ChangeDepartmentOfUser(userIds, newDepartmentId, createId); return(true); }
/// <summary> /// 获取当前部门以外的用户列表 by wangligui /// </summary> public List <DepartmentUserResponse> GetUserOutDepartment(int departmentId, int loginUserId) { var isSysAdmin = CommonAction.IsSysAdmin(loginUserId); return(DepartmentUserDbAction.GetUserOutDepartment(departmentId, loginUserId, isSysAdmin)); }