public LoginUserVM Login(string userName, string password) { var user = _repository.FindSingle(u => u.Account == userName); if (user == null) { throw new Exception("用户帐号不存在"); } user.CheckPassword(password); var loginVM = new LoginUserVM { User = user }; //用户角色 var userRoleIds = _relevanceRepository.Find(u => u.FirstId == user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList(); //用户角色与自己分配到的模块ID var moduleIds = _relevanceRepository.Find( u => (u.FirstId == user.Id && u.Key == "UserModule") || (u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); //用户角色与自己分配到的菜单ID var elementIds = _relevanceRepository.Find( u => (u.FirstId == user.Id && u.Key == "UserElement") || (u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); //得出最终用户拥有的模块 loginVM.Modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).MapToList <ModuleView>(); //模块菜单权限 foreach (var module in loginVM.Modules) { module.Elements = _moduleElementRepository.Find(u => u.ModuleId == module.Id && elementIds.Contains(u.Id)).OrderBy(u => u.Sort).ToList(); } //用户角色与自己分配到的资源ID var resourceIds = _relevanceRepository.Find( u => (u.FirstId == user.Id && u.Key == "UserResource") || (u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); loginVM.Resources = _resourceRepository.Find(u => resourceIds.Contains(u.Id)).ToList(); //用户角色与自己分配到的机构ID var orgids = _relevanceRepository.Find( u => (u.FirstId == user.Id && u.Key == "UserAccessedOrg") || (u.Key == "RoleAccessedOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); loginVM.AccessedOrgs = _orgRepository.Find(u => orgids.Contains(u.Id)).ToList(); return(loginVM); }
public void GetUserAccessed(string name) { if (name == "System") { _modules = _moduleRepository.Find(null).ToList(); _moduleElements = _moduleElementRepository.Find(null).ToList(); _resources = _resourceRepository.Find(null).OrderBy(u => u.SortNo).ToList(); _orgs = _orgRepository.Find(null).OrderBy(u => u.SortNo).ToList(); } else { _user = _repository.FindSingle(u => u.Account == name); //用户角色 var userRoleIds = _relevanceRepository.Find(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList(); //用户角色与自己分配到的模块ID var moduleIds = _relevanceRepository.Find( u => (u.FirstId == _user.Id && u.Key == "UserModule") || (u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); //用户角色与自己分配到的菜单ID var elementIds = _relevanceRepository.Find( u => (u.FirstId == _user.Id && u.Key == "UserElement") || (u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); //得出最终用户拥有的模块 _modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList(); //模块菜单权限 _moduleElements = _moduleElementRepository.Find(u => elementIds.Contains(u.Id)).ToList(); //用户角色与自己分配到的资源ID var resourceIds = _relevanceRepository.Find( u => (u.FirstId == _user.Id && u.Key == "UserResource") || (u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); _resources = _resourceRepository.Find(u => resourceIds.Contains(u.Id)).ToList(); //用户角色与自己分配到的机构ID var orgids = _relevanceRepository.Find( u => (u.FirstId == _user.Id && u.Key == "UserAccessedOrg") || (u.Key == "RoleAccessedOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList(); _orgs = _orgRepository.Find(u => orgids.Contains(u.Id)).ToList(); } }
/// <summary> /// 获取当前组织的所有下级组织 /// </summary> private int[] GetSubOrgIds(int orgId) { var org = _orgRepository.FindSingle(u => u.Id == orgId); var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); return(orgs); }
private string GetEnumOrganizationValue(Guid value) { var orgInfo = _orgRepo.Find(value); if (orgInfo == null) { return(null); } return(orgInfo.Name); }
/// <summary> /// 部门的直接子部门 /// <para>TODO:可以根据用户的喜好决定选择LoadAllChildren或LoadDirectChildren</para> /// </summary> /// <param name="orgId">The org unique identifier.</param> /// <returns>IEnumerable{Org}.</returns> public IList <Org> LoadDirectChildren(int orgId) { return(_repository.Find(u => u.ParentId == orgId).ToList()); }
internal UserInfo GetUserInfo(IDataContext context, Worker user) { // Guid? orgUnitTypeId = null; // string orgUnitTypeName = ""; // string positionName = ""; var positionId = user.OrgPosition_Id; /* * if (!user.Org_PositionsReference.IsLoaded) user.Org_PositionsReference.Load(); * if (user.Org_Positions != null) * { * positionName = user.Org_Positions.Full_Name; * if (user.Org_Positions.Parent_Id != null) * { * var orgUnit = context.Defs<Org_Unit>() * .FirstOrDefault(ou => ou.Id == user.Org_Positions.Parent_Id); * * if (orgUnit != null) * { * orgUnitTypeId = user.Org_Positions.Parent_Id; * orgUnitTypeName = orgUnit.Full_Name; * } * } * // if (!user.Org_Positions.ParentReference.IsLoaded) user.Org_Positions.ParentReference.Load(); * // if (user.Org_Positions.Parent is Org_Unit) * // { * // orgUnitTypeId = user.Org_Positions.Parent_Id; * // orgUnitTypeName = user.Org_Positions.Parent.Full_Name; * // } * } */ var orgPosition = positionId != null?OrgRepo.FindOrgPosition((Guid)positionId) : null; var orgUnitType = orgPosition != null && orgPosition.OrgTypeId != null ? OrgRepo.FindOrgType((Guid)orgPosition.OrgTypeId) : null; /*Organization organization = null; * * if (user.Parent_Id != null) * { * organization = context.Defs<Organization>() * .FirstOrDefault(o => o.Id == user.Parent_Id); * }*/ var orgInfo = user.Parent_Id != null?OrgRepo.Find((Guid)user.Parent_Id) : null; return(new UserInfo { Id = user.Id, UserName = user.User_Name, FirstName = user.First_Name ?? "", LastName = user.Last_Name ?? "", Position = orgPosition, PositionId = positionId, PositionName = orgPosition != null ? orgPosition.Name : String.Empty, OrgUnitTypeId = orgPosition != null ? orgPosition.OrgTypeId : null, OrgUnitTypeName = orgUnitType != null ? orgUnitType.Name : String.Empty, Organization = orgInfo, OrganizationId = orgInfo != null ? orgInfo.Id : (Guid?)null, OrganizationTypeId = orgInfo != null ? orgInfo.TypeId : null, OrganizationName = orgInfo != null ? orgInfo.Name : String.Empty, OrganizationCode = orgInfo != null ? orgInfo.Code : String.Empty, LanguageId = user.Language_Id ?? 0 }); }