@@ -17,7 +17,8 @@ public static class ServiceExtensions
17
17
{
18
18
public static void ConfigureSqlContext ( this IServiceCollection services , IConfiguration configuration )
19
19
{
20
- var connectionString = configuration [ "ConnectionStrings:Database" ] ;
20
+ //var connectionString = configuration["ConnectionStrings:Database"];
21
+ var connectionString = "Server=127.0.0.1\\ mssql,1433;Database=WorkoutTrackerDB;User=sa;Password=/Password12;TrustServerCertificate=Yes" ;
21
22
22
23
services . AddDbContext < ApplicationContext > ( opt =>
23
24
{
@@ -42,8 +43,9 @@ public static void ConfigureFilters(this IServiceCollection services)
42
43
{
43
44
services . AddScoped < ValidationFilterAttribute > ( ) ;
44
45
services . AddScoped < ExerciseExistsFilterAttribute > ( ) ;
45
- services . AddScoped < WorkoutExistsFilterAttribute > ( ) ;
46
+ services . AddScoped < WorkoutForUserExistsFilterAttribute > ( ) ;
46
47
services . AddScoped < WorkoutExerciseExistsFilterAttribute > ( ) ;
48
+ services . AddScoped < UserExistsFilterAttribute > ( ) ;
47
49
}
48
50
49
51
public static void ConfigureSwagger ( this IServiceCollection services )
@@ -85,9 +87,19 @@ public static void ConfigureAuthenticationAndAuthorization(this IServiceCollecti
85
87
public static async Task SeedDatabase ( this WebApplication app )
86
88
{
87
89
using var scope = app . Services . CreateScope ( ) ;
88
- var dbSeeder = scope . ServiceProvider . GetRequiredService < AuthDbSeeder > ( ) ;
90
+ var authDbSeeder = scope . ServiceProvider . GetRequiredService < AuthDbSeeder > ( ) ;
91
+ var dbSeeder = scope . ServiceProvider . GetRequiredService < DbSeeder > ( ) ;
89
92
93
+ await authDbSeeder . SeedAsync ( ) ;
90
94
await dbSeeder . SeedAsync ( ) ;
91
95
}
96
+
97
+ public static void RunMigrations ( this WebApplication app )
98
+ {
99
+ using var scope = app . Services . CreateScope ( ) ;
100
+ var dbContext = scope . ServiceProvider . GetRequiredService < ApplicationContext > ( ) ;
101
+
102
+ dbContext . Database . Migrate ( ) ;
103
+ }
92
104
}
93
105
}
0 commit comments