コード例 #1
0
        public async Task AddUserToTenantAsync(Tenant tenant, User user, CancellationToken cancellationToken = default)
        {
            NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenant);
            NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(user);

            await tenantUserRepository.AddAsync(tenant.TenantId, user.UserId);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        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);
        }