Skip to content

Commit b559f53

Browse files
committed
Fix about some async calls.
1 parent 1f971bc commit b559f53

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using IdentityServer4.EntityFramework.DbContexts;
22
using IdentityServer4.EntityFramework.Mappers;
33
using Microsoft.eShopOnContainers.Services.Identity.API.Configuration;
4+
using Microsoft.EntityFrameworkCore;
45
using Microsoft.Extensions.Configuration;
56
using System.Collections.Generic;
67
using System.Linq;
@@ -24,33 +25,22 @@ public async Task SeedAsync(ConfigurationDbContext context, IConfiguration confi
2425
{"OrderingApi", configuration.GetValue<string>("OrderingApiClient")}
2526
};
2627

27-
if (!context.Clients.Any())
28+
if (!await context.Clients.AnyAsync())
2829
{
29-
foreach (var client in Config.GetClients(clientUrls))
30-
{
31-
await context.Clients.AddAsync(client.ToEntity());
32-
}
33-
await context.SaveChangesAsync();
30+
context.Clients.AddRange(Config.GetClients(clientUrls).Select(client => client.ToEntity()));
3431
}
3532

36-
if (!context.IdentityResources.Any())
33+
if (!await context.IdentityResources.AnyAsync())
3734
{
38-
foreach (var resource in Config.GetResources())
39-
{
40-
await context.IdentityResources.AddAsync(resource.ToEntity());
41-
}
42-
await context.SaveChangesAsync();
35+
context.IdentityResources.AddRange(Config.GetResources().Select(resource => resource.ToEntity()));
4336
}
4437

45-
if (!context.ApiResources.Any())
38+
if (!await context.ApiResources.AnyAsync())
4639
{
47-
foreach (var api in Config.GetApis())
48-
{
49-
await context.ApiResources.AddAsync(api.ToEntity());
50-
}
51-
52-
await context.SaveChangesAsync();
40+
context.ApiResources.AddRange(Config.GetApis().Select(api => api.ToEntity()));
5341
}
42+
43+
await context.SaveChangesAsync();
5444
}
5545
}
5646
}

0 commit comments

Comments
 (0)