apikey.creationdate

broken/ef
Paul Schneider 3 years ago
parent 915736c4e2
commit bb02706773
5 changed files with 47 additions and 10 deletions

@ -24,6 +24,27 @@
"sourceFileMap": { "sourceFileMap": {
"/Views": "${workspaceFolder}/Views" "/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"
}
} }
] ]
} }

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@ -66,7 +67,8 @@ namespace nuget_host.Controllers
ModelState.AddModelError(null, "Maximum key count reached"); ModelState.AddModelError(null, "Maximum key count reached");
return View(); 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); _ = dbContext.ApiKeys.Add(newKey);
_ = await dbContext.SaveChangesAsync(); _ = await dbContext.SaveChangesAsync();
return View("Details", new DetailModel { Name = newKey.Name, return View("Details", new DetailModel { Name = newKey.Name,

@ -60,7 +60,8 @@ namespace nuget_host
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // 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()) if (env.IsDevelopment())
{ {
@ -73,12 +74,7 @@ namespace nuget_host
app.UseHsts(); app.UseHsts();
try try
{ {
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>() dbContext.Database.Migrate();
.CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
}
} }
catch (TargetInvocationException ex) catch (TargetInvocationException ex)
{ {

@ -0,0 +1,18 @@
{
"Nuget": {
"ExternalUrl" : "<http://localhost:5000/packages",
"PackagesRootDir" : "packages",
"MaxUserKeyCount": 5
},
"Smtp": {
"Server": "localhost",
"Port": 25,
"SenderName": "Paul Schneider",
"SenderEmail": "paul@pschneider.fr"
},
"Kestrel": {
"Endpoints": {
"web": ""
}
}
}

@ -19,8 +19,8 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.1" />
<PackageReference Include="MailKit" Version="2.11.1" /> <PackageReference Include="MailKit" Version="2.11.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1" IncludeAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" IncludeAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" IncludeAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" IncludeAssets="All" />
</ItemGroup> </ItemGroup>

Loading…