0
rvanwoezik created
ASP.NET CORE & Angular (single solution) .NET 5.0 v10.2.0
I have the situation where i create a tenant for each subcribed
In the host i would like to get a list of all users across all tenants including there tenant name, so i made a private function to fill tenant names, but this gives an error, can't find tenant
[HttpPost]
public async Task<PagedResultDto<UserListDto>> GetUsers(GetUsersInput input)
{
if (AbpSession.MultiTenancySide == MultiTenancySides.Host)
{
using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
var query = GetUsersFilteredQuery(input);
var userCount = await query.CountAsync();
var users = await query
.OrderBy(input.Sorting)
.PageBy(input)
.ToListAsync();
var userListDtos = ObjectMapper.Map<List<UserListDto>>(users);
await FillRoleNames(userListDtos);
await FillTenantNames(userListDtos);
return new PagedResultDto<UserListDto>(
userCount,
userListDtos
);
}
}
else
{
var query = GetUsersFilteredQuery(input);
var userCount = await query.CountAsync();
var users = await query
.OrderBy(input.Sorting)
.PageBy(input)
.ToListAsync();
var userListDtos = ObjectMapper.Map<List<UserListDto>>(users);
await FillRoleNames(userListDtos);
return new PagedResultDto<UserListDto>(
userCount,
userListDtos
);
}
}
private async Task FillTenantNames(IReadOnlyCollection<UserListDto> userListDtos)
{
foreach (var user in userListDtos)
{
if (user.TenantId > 0)
{
var tenant = await TenantManager.GetByIdAsync(user.TenantId);
user.TenantName = tenant.TenancyName;
}
else
{
user.TenantName = "HOST";
}
}
}
Please advice
1 Answer(s)
-
0
Hi,
It will be better to query
AbpUserAccounts
table to get those information. This is a Host side table, so you can easil access it from a host user.