//获取组中的学习顾问 private static List <UserLiteDto> GetGroupConsultant(int userId, bool isGettingStudyConsultant) { //----------------------- // 获取所有顾问 //----------------------- var allConsultant = GetConsultant(-1, isGettingStudyConsultant); //----------------------- // 获取用户所属部门所有用户 //----------------------- var engine = PermissionDb.CreateEngine(); var dbDepartments = DepartmentDbAction.GetDepartments(userId); var departmentIds = new List <int>(100); GetUserDepartmentIds(dbDepartments, departmentIds); var query3 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId where departmentIds.Contains(depUser.DeparentId) select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo, Sex = user.Sex }; //----------------------- // 取所有顾问和当前部门所有用户的交集并返回 //----------------------- var depUsers = query3.ToArray(); return(allConsultant.Intersect(depUsers).ToList()); }
public List <UserLiteDto> GetUsersByFunctionKey(string functionKey, int userId) { var engine = PermissionDb.CreateEngine(); var funcId = engine.Esmart_Sys_Functions.Where(n => n.FunctionKey == functionKey).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 where user.Isleave != 1 && user.IsDelete != 1 && roleFunc.FunctionId == funcId 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 where user.Isleave != 1 && user.IsDelete != 1 && userFunc.FunctionId == funcId select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }); List <UserLiteDto> lstUsers = query1.ToList(); var allUsers = lstUsers.Where((x, i) => lstUsers.FindIndex(f => f.UserID == x.UserID) == i).ToList(); if (userId > 0) { //----------------------- // 获取用户所属部门所有用户 //----------------------- var dbDepartments = DepartmentDbAction.GetDepartments(userId); var departmentIds = new List <int>(100); GetUserDepartmentIds(dbDepartments, departmentIds); var query2 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId where departmentIds.Contains(depUser.DeparentId) select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo, Sex = user.Sex }; var depUsers = query2.ToArray(); return(allUsers.Intersect(depUsers).ToList()); } return(allUsers); }
/// <summary> /// 根据用户Id获取部门列表 /// 用户Id->RoleId->DepartmentId /// </summary> public List <DepartmentResponse> GetDepartmentsByUserId(int userId, int withUsers) { var departments = DepartmentDbAction.GetDepartments(CommonAction.IsSysAdmin(userId) ? null : (int?)userId); var result = new List <DepartmentResponse>(10); DepartmentDto(departments, result, withUsers > 0); return(result); }
public DepartmentResponse GetDepartmentResponse(int id) { var _response = new DepartmentResponse(); var _sysDepartments = DepartmentDbAction.GetDeparentById(id); _response.DeparentId = _sysDepartments.DeparentId; _response.Name = _sysDepartments.Name; _response.Remark = _sysDepartments.Remark; _response.CreateId = _sysDepartments.CreateId; _response.CreateTime = _sysDepartments.CreateTime; _response.IsDelete = _sysDepartments.IsDelete; _response.ParentId = _sysDepartments.ParentId; return(_response); }
public List <UserLiteDto> GetStudyConsultantLeader(int userId) { var engine = PermissionDb.CreateEngine(); var depId = engine.Esmart_Sys_Department_User.Where(n => n.UserId == userId).Select(n => n.DeparentId).FirstOrDefault(); //所给用户不属于任何部门 if (depId < 1) { return(new List <UserLiteDto>(0)); } var query = from userRole in engine.Esmart_Sys_User_Roles join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId where userRole.UserId == userId && role.RoleName == BuiltinRoles.StudyConsultantAdmin select userRole.UserId; //所给用户不是学习顾问 if (!query.Any()) { return(new List <UserLiteDto>(0)); } //获取所有的上级部门 var parentDepartmentIds = DepartmentDbAction.GetParentDepartments(userId).Select(n => n.DeparentId).ToList(); var query2 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId join userRole in engine.Esmart_Sys_User_Roles on user.UserID equals userRole.UserId join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId where user.IsDelete != 1 && user.Isleave != 1 //本组学习顾问组长或值班组长、上级部门的学习顾问主管、学习顾问经理 && ((depUser.DeparentId == depId && (role.RoleName == BuiltinRoles.StudyConsultantAdmin || role.RoleName == BuiltinRoles.StudyConsultantAdmin)) || (parentDepartmentIds.Contains(depId) && role.RoleName == BuiltinRoles.StudyConsultantAdmin) || role.RoleName == BuiltinRoles.StudyConsultantAdmin) select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }; return(query2.Distinct().ToList()); }
/// <summary> /// 修改 /// </summary> /// <returns>返回值</returns> public int Update(DepartmentRequest request) { var result = 0; var model = new Esmart_Sys_Departments(); if (request != null) { model.DeparentId = request.DeparentId; model.CreateId = request.CreateId; model.CreateTime = request.CreateTime; model.Name = request.Name; model.ParentId = request.ParentId; model.Remark = request.Remark; model.SortNo = request.SortNo; model.IsDelete = request.IsDelete; result = DepartmentDbAction.Update(model); } return(result); }
/// <summary> /// 添加 /// </summary> /// <returns>返回值</returns> public int Add(DepartmentRequest request) { var model = new Esmart_Sys_Departments(); if (request != null) { model.DeparentId = request.DeparentId; model.CreateId = request.CreateId; model.CreateTime = request.CreateTime; model.Name = request.Name; model.ParentId = request.ParentId; model.Remark = request.Remark; model.SortNo = request.SortNo; model.IsDelete = request.IsDelete; DepartmentDbAction.Add(model); return(model.DeparentId); } return(-1); }
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); }
/// <summary> /// 删除 /// </summary> /// <param name="id">部门ID</param> /// <returns>返回值</returns> public int Delete(int id) { return(DepartmentDbAction.Delete(id)); }