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)); }
public override bool IsValid(object value) { SaveTenant tenant = (SaveTenant)value; if (tenant.IsDefaultConnection == false && string.IsNullOrWhiteSpace(tenant.ConnectionString)) { return(false); } return(true); }
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)); }
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; }
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; }
public Task <IActionResult> Put( [FromServices] IPutTenantCommand command, string tenantId, [FromBody] SaveTenant tenant, CancellationToken cancellationToken) => command.ExecuteAsync(tenantId, tenant, cancellationToken);
public Task <IActionResult> Post( [FromServices] IPostTenantCommand command, [FromBody] SaveTenant tenant, CancellationToken cancellationToken) => command.ExecuteAsync(tenant);