From bb027067735c7236af417c6fbeb0677e3cbd115a Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 9 May 2021 01:52:46 +0100 Subject: [PATCH] apikey.creationdate --- .vscode/launch.json | 21 +++++++++++++++++++++ Controllers/ApiKeysController.cs | 4 +++- Startup.cs | 10 +++------- appsettings.Production.json | 18 ++++++++++++++++++ nuget-host.csproj | 4 ++-- 5 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 appsettings.Production.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 707b99f..6f22741 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,6 +24,27 @@ "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } + }, + { + "name": ".NET Core Launch (prod)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/nuget-host.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + "requireExactSource": false, + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\\\bNow listening on:\\\\s+(https?://\\\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Production" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } } ] } \ No newline at end of file diff --git a/Controllers/ApiKeysController.cs b/Controllers/ApiKeysController.cs index 5622df7..f4ad220 100644 --- a/Controllers/ApiKeysController.cs +++ b/Controllers/ApiKeysController.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -66,7 +67,8 @@ namespace nuget_host.Controllers ModelState.AddModelError(null, "Maximum key count reached"); return View(); } - ApiKey newKey = new ApiKey { UserId = userid, Name = model.Name }; + ApiKey newKey = new ApiKey { UserId = userid, Name = model.Name, + CreationDate = DateTime.Now }; _ = dbContext.ApiKeys.Add(newKey); _ = await dbContext.SaveChangesAsync(); return View("Details", new DetailModel { Name = newKey.Name, diff --git a/Startup.cs b/Startup.cs index 4196cc1..c1c133f 100644 --- a/Startup.cs +++ b/Startup.cs @@ -60,7 +60,8 @@ namespace nuget_host } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env) + public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, + ApplicationDbContext dbContext) { if (env.IsDevelopment()) { @@ -73,12 +74,7 @@ namespace nuget_host app.UseHsts(); try { - using (var serviceScope = app.ApplicationServices.GetRequiredService() - .CreateScope()) - { - serviceScope.ServiceProvider.GetService() - .Database.Migrate(); - } + dbContext.Database.Migrate(); } catch (TargetInvocationException ex) { diff --git a/appsettings.Production.json b/appsettings.Production.json new file mode 100644 index 0000000..1c4d40c --- /dev/null +++ b/appsettings.Production.json @@ -0,0 +1,18 @@ +{ + "Nuget": { + "ExternalUrl" : " - - + +