public async Task <IEnumerable <OrganizationDto> > GetAllAsync(string name = null) { var orgs = await _orgRepo.GetAllAsync(name); if (orgs == null) { return(Enumerable.Empty <OrganizationDto>()); } return(orgs.Select(itm => new OrganizationDto { Id = itm.Id, Address = itm.Address, Desc = itm.Desc, IsEnabled = itm.Enabled, Mobile = itm.Mobile, Name = itm.Name, ParentId = itm.Parent == null ? String.Empty : itm.Parent.Id, Roles = itm.OrganizationRoles.Select(role => new RoleDto { Id = role.RoleId, Name = role.Role.Name, IsAdmin = role.Role.IsAdmin, ClientId = role.Role.ClientId }).ToList(), CreatedAt = itm.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss") })); }
public async Task <IEnumerable <OrganizationDto> > GetOrgsAsync(string id) { if (String.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } var user = await _userRepo.GetAsync(id); if (user == null) { throw new IamException(HttpStatusCode.BadRequest, "用户不存在"); } if (user.UserOrganizations == null || !user.UserOrganizations.Any()) { return(Enumerable.Empty <OrganizationDto>()); } var orgs = (await _orgRepo.GetAllAsync(isEnabled: true)) .Select(itm => _mapper.Map <OrganizationDto>(itm)); var orgsInTree = orgs.GetTreeLayout(); var orgIds = user.UserOrganizations.Select(itm => itm.OrganizationId); return(orgsInTree.FilterTree(orgIds)); }