From 52950d599978d94756591ce24a4bafb31f5949ce Mon Sep 17 00:00:00 2001 From: Fabi Date: Thu, 30 Jan 2025 09:37:34 +0200 Subject: [PATCH] environment de dev --- Chir.ia_project/Chir.ia_project.sln | 1 + Chir.ia_project/Controllers/ListingController.cs | 1 + Chir.ia_project/Extensions.cs | 10 +++++++++- Chir.ia_project/appsettings.Development.json | 11 +++++++++++ Chir.ia_project/appsettings.Local.json | 11 +++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Chir.ia_project/appsettings.Development.json create mode 100644 Chir.ia_project/appsettings.Local.json diff --git a/Chir.ia_project/Chir.ia_project.sln b/Chir.ia_project/Chir.ia_project.sln index a555b99..dd37260 100644 --- a/Chir.ia_project/Chir.ia_project.sln +++ b/Chir.ia_project/Chir.ia_project.sln @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chir.ia_project", "Chir.ia_ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0D0B89B9-D1AB-4578-B3E5-7274897CEAB7}" ProjectSection(SolutionItems) = preProject + appsettings.Development.json = appsettings.Development.json AppSettings.json = AppSettings.json EndProjectSection EndProject diff --git a/Chir.ia_project/Controllers/ListingController.cs b/Chir.ia_project/Controllers/ListingController.cs index b04cf11..eae9fb4 100644 --- a/Chir.ia_project/Controllers/ListingController.cs +++ b/Chir.ia_project/Controllers/ListingController.cs @@ -70,6 +70,7 @@ public async Task GetById(Guid id) } [HttpGet] + [Authorize] public async Task IndexSwipe() { var userId = userManager.GetUserId(User); diff --git a/Chir.ia_project/Extensions.cs b/Chir.ia_project/Extensions.cs index 4bb0096..1379e33 100644 --- a/Chir.ia_project/Extensions.cs +++ b/Chir.ia_project/Extensions.cs @@ -12,7 +12,15 @@ public static class Extensions { public static IServiceCollection AddDbContextAndIdentity(this IServiceCollection services, IConfiguration configuration, IHostEnvironment environment) { - services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); + if (environment.IsDevelopment()) + { + services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING"))); + } + else + { + services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); + } + services.AddRazorPages(); services.AddDefaultIdentity() .AddEntityFrameworkStores(); diff --git a/Chir.ia_project/appsettings.Development.json b/Chir.ia_project/appsettings.Development.json new file mode 100644 index 0000000..d5de6af --- /dev/null +++ b/Chir.ia_project/appsettings.Development.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "AZURE_SQL_CONNECTIONSTRING": "Data Source=chiriaserver.database.windows.net;Initial Catalog=chiria;Authentication=Active Directory Default; Encrypt=True;" + } +} \ No newline at end of file diff --git a/Chir.ia_project/appsettings.Local.json b/Chir.ia_project/appsettings.Local.json new file mode 100644 index 0000000..97a6deb --- /dev/null +++ b/Chir.ia_project/appsettings.Local.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Chir.ia_db;Integrated Security=True;Multiple Active Result Sets=True" + } +} \ No newline at end of file