public async Task AddUriAsync(string tenantKey, string uri, TenantUriType uriType) { var tenant = await _identityDb.Tenants.FirstOrDefaultAsync(x => x.Key == tenantKey); if (tenant == null) { throw new NullReferenceException($"Tenant {tenantKey} does not exist."); } uri = NormalizeTenantUri(uri); var exists = await _identityDb.TenantUris .AnyAsync(x => x.TenantId == tenantKey && x.Uri == uri && x.Type == uriType); if (!exists) { _identityDb.TenantUris.Add(new TenantUri { Id = KeyGen.NewGuid(), TenantId = tenant.Id, Type = uriType, Uri = uri }); await _identityDb.SaveChangesAsync(); } }
public async Task <IEnumerable <string> > GetUrisAsync(string tenantKey, TenantUriType uriType) { Ensure.Argument.NotNull(tenantKey); Ensure.Argument.NotNull(uriType); return(await _identityDb.TenantUris .Where(x => x.Tenant.Key == tenantKey && x.Type == uriType) .Select(x => x.Uri) .ToListAsync()); }
public async Task RemoveUriAsync(string tenantKey, string uri, TenantUriType uriType) { var tenant = await _identityDb.Tenants.FirstOrDefaultAsync(x => x.Key == tenantKey); if (tenant == null) { throw new NullReferenceException($"Tenant {tenantKey} does not exist."); } uri = NormalizeTenantUri(uri); var uriEntry = await _identityDb.TenantUris.FirstOrDefaultAsync(x => x.TenantId == tenant.Id && x.Type == uriType && x.Uri == uri ); if (uriEntry != null) { _identityDb.TenantUris.Remove(uriEntry); await _identityDb.SaveChangesAsync(); } }