Base solution for your next web application
Open Closed

How to Get List of Tenants using Organization Id #11492

maharatha created

I have added an OrganizationId ForeignKey to the tenant table.

I am now getting the list of Organization for the user

var organizationList = await UserManager.GetOrganizationUnitsAsync(await UserManager.GetUserByIdAsync(AbpSession.UserId.Value));

var query = TenantManager.Tenants
                .Include(t => t.Edition)
                .Include(t =>t.OrganizationUnit)
                .WhereIf(!input.Filter.IsNullOrWhiteSpace(), t => t.Name.Contains(input.Filter) || t.TenancyName.Contains(input.Filter))
                .WhereIf(input.CreationDateStart.HasValue, t => t.CreationTime >= input.CreationDateStart.Value)
                .WhereIf(input.CreationDateEnd.HasValue, t => t.CreationTime <= input.CreationDateEnd.Value)
                .WhereIf(input.SubscriptionEndDateStart.HasValue, t => t.SubscriptionEndDateUtc >= input.SubscriptionEndDateStart.Value.ToUniversalTime())
                .WhereIf(input.SubscriptionEndDateEnd.HasValue, t => t.SubscriptionEndDateUtc <= input.SubscriptionEndDateEnd.Value.ToUniversalTime())
                .WhereIf(input.EditionIdSpecified, t => t.EditionId == input.EditionId);

How do I filter by OrganizationList here ?

1 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi @maharatha,

    I tihnk you can use a filter like this;

    .WhereIf(organizationList.Any(), t => organizationList.Any(o=> t.OrganizationId == o.Id))