コード例 #1
0
        public async Task <IActionResult> ExecuteAsync(
            string tenantId,
            SaveTenant saveTenant,
            CancellationToken cancellationToken = default)
        {
            var tenant = await tenantRepository.Get(tenantId, cancellationToken).ConfigureAwait(false);

            if (tenant is null)
            {
                return(new NotFoundResult());
            }
            if (saveTenant.IsDefaultConnection == false)
            {
                if (this.TestConnection(host.TenantInfo(), saveTenant.ConnectionString) == false)
                {
                    return(new StatusCodeResult(417));//Expectation failed
                }
            }
            saveTenantToTenantMapper.Map(saveTenant, tenant);
            tenant = await tenantRepository.Update(tenant, cancellationToken).ConfigureAwait(false);

            var tenantViewModel = tenantToTenantMapper.Map(tenant);

            return(new OkObjectResult(tenantViewModel));
        }
コード例 #2
0
        public override bool IsValid(object value)
        {
            SaveTenant tenant = (SaveTenant)value;

            if (tenant.IsDefaultConnection == false &&
                string.IsNullOrWhiteSpace(tenant.ConnectionString))
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        public async Task <IActionResult> ExecuteAsync(SaveTenant parameter, CancellationToken cancellationToken = default)
        {
            if (parameter.IsDefaultConnection)
            {
                parameter.ConnectionString = host.TenantInfo().ConnectionString;
            }
            else
            {
                if (this.TestConnection(host.TenantInfo(), parameter.ConnectionString) == false)
                {
                    return(new StatusCodeResult(417));//Expectation failed
                }
            }

            var tenant = saveTenantToTenantMapper.Map(parameter);

            tenant = await tenantRepository.Add(tenant, out RepositoryError error, cancellationToken).ConfigureAwait(false);

            if (error == RepositoryError.AlreadyExists)
            {
                return(new ConflictResult());
            }
            if (error != RepositoryError.None)
            {
                return(new StatusCodeResult(500));
            }
            var tenantViewModel = tenantToTenantMapper.Map(tenant);

            if (parameter.IsDefaultConnection == true)
            {
                await bus.Publish <TenantCreated>(new
                {
                    Id           = tenant.Id,
                    CreationTime = tenant.Created.UtcDateTime
                });
            }
            else
            {
                await bus.ScheduleMessage <TenantCreatedNotDefault>(
                    new Uri("loopback://localhost/tenant-created-notdefault"),
                    DateTime.UtcNow.AddSeconds(30),
                    (TenantCreatedNotDefault)(new
                {
                    Id = tenant.Id,
                    CreationTime = tenant.Created.UtcDateTime
                }));
            }

            return(new CreatedAtRouteResult(
                       TenantControllerRoute.GetTenant,
                       new { tenantId = tenantViewModel.Id },
                       tenantViewModel));
        }
コード例 #4
0
 public void Map(Data.Tenant source, SaveTenant destination)
 {
     if (source is null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (destination is null)
     {
         throw new ArgumentNullException(nameof(destination));
     }
     destination.ConnectionString    = source.ConnectionString;
     destination.Email               = source.Email;
     destination.Identifier          = source.Identifier;
     destination.IsDefaultConnection = false;//TODO check
     destination.Name  = source.Name;
     destination.Phone = source.Phone;
 }
コード例 #5
0
        public void Map(SaveTenant source, Data.Tenant destination)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (destination is null)
            {
                throw new ArgumentNullException(nameof(destination));
            }
            var now = clock.UtcNow;

            if (destination.Created == DateTimeOffset.MinValue)
            {
                destination.Created = now;
            }
            destination.ConnectionString = source.ConnectionString;
            destination.Identifier       = source.Identifier;
            destination.Name             = source.Name;
            destination.Phone            = source.Phone;
            destination.Email            = source.Email;
            destination.Modified         = now;
        }
コード例 #6
0
 public Task <IActionResult> Put(
     [FromServices] IPutTenantCommand command,
     string tenantId,
     [FromBody] SaveTenant tenant,
     CancellationToken cancellationToken) => command.ExecuteAsync(tenantId, tenant, cancellationToken);
コード例 #7
0
 public Task <IActionResult> Post(
     [FromServices] IPostTenantCommand command,
     [FromBody] SaveTenant tenant,
     CancellationToken cancellationToken) => command.ExecuteAsync(tenant);