public async Task AddUserToTenantAsync(Tenant tenant, User user, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenant); NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(user); await tenantUserRepository.AddAsync(tenant.TenantId, user.UserId); }
public async Task <bool> IsUserInTenantAsync(Tenant tenant, User user, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenant.TenantId); NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(user.UserId); return(await tenantUserRepository.IsUserInTenantAsync(tenant.TenantId, user.UserId, cancellationToken)); }
/// <summary> /// store tenant infomation /// </summary> /// <param name="tenant">tenant object</param> public async Task StoreTenantAsync(Tenant tenant, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenant); var addressId = await addressRepository.AddAsync(tenant.Address.CreateDtoAddress()); await tenantRepository.AddAsync(tenant.CreateDtoTenant(addressId), cancellationToken); }
public async Task <IEnumerable <User> > GetAllUsersInTenantAsync(Guid tenantId, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenantId); var userIds = await tenantUserRepository.ListAsync(tenantId, cancellationToken); var users = await userRepository.GetUsersAsync(userIds, cancellationToken); return(UserMapping.ConvertDtoUsers(users)); }
public async Task <IEnumerable <Tenant> > GetTenantsAsync(Guid userId, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(userId); var tenantIds = await tenantUserRepository.GetAllTenantIdsForUserAsync(userId, cancellationToken); var dtoTenants = await tenantRepository.ListAsync(tenantIds, cancellationToken); return(dtoTenants.ConvertDtoTenantsToTenants()); }
/// <summary> /// Get all tenants by their id /// </summary> /// <param name="tenantIds"></param> /// <returns></returns> public async Task <IEnumerable <Tenant> > GetTenantsAsync(IEnumerable <Guid> tenantIds, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenantIds); var dtoTenants = await tenantRepository.ListAsync(tenantIds); var tenants = await MapAddressesToTenants(dtoTenants); if (dtoTenants == null) { throw new SqlEntityNullReferenceException(nameof(dtoTenants), nameof(tenantIds)); } return(tenants); }
public async Task <Tenant> GetTenantAsync(Guid tenantId, CancellationToken cancellationToken = default) { NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenantId); var dtoTenant = await tenantRepository.GetAsync(tenantId, cancellationToken); var dtoAddress = await addressRepository.GetAsync(dtoTenant.AddressId, cancellationToken); if (dtoAddress == null) { throw new SqlEntityNullReferenceException(nameof(dtoAddress), dtoAddress.AddressId.ToString()); } if (dtoTenant == null) { throw new SqlEntityNullReferenceException(nameof(dtoAddress), dtoTenant.TenantId.ToString()); } var tenant = TenantMapping.ConvertDtoTenantToTenant(dtoTenant); tenant.Address = AddressMapping.ConvertDtoAddressToAddress(dtoAddress); return(tenant); }