Initial commit
|
|
@ -10,4 +10,9 @@
|
|||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- change Sqlite to SqlServer if you prefer -->
|
||||
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -9,11 +9,21 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Minimal.WebApi": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5003",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
|
|
|||
BIN
vs4win/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -6,6 +6,14 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="wwwroot\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- change Sqlite to SqlServer if you prefer -->
|
||||
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -8,7 +8,16 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.BlazorServer": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5004",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -8,11 +8,19 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.BlazorWasm.Server": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5006",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||
"applicationUrl": "https://localhost:5007;http://localhost:5006",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
|
@ -27,4 +35,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -75,14 +75,16 @@ namespace Northwind.Mvc.Controllers
|
|||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> ProductDetail(int? id)
|
||||
public async Task<IActionResult> ProductDetail(int? id, string alertstyle = "success")
|
||||
{
|
||||
ViewData["alertstyle"] = alertstyle;
|
||||
|
||||
if (!id.HasValue)
|
||||
{
|
||||
return BadRequest("You must pass a product ID in the route, for example, /Home/ProductDetail/21");
|
||||
}
|
||||
|
||||
Product? model = await db.Products
|
||||
Product? model = await db.Products.Include(p => p.Category)
|
||||
.SingleOrDefaultAsync(p => p.ProductId == id);
|
||||
|
||||
if (model is null)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class RolesController : Controller
|
|||
{
|
||||
await roleManager.CreateAsync(new IdentityRole(AdminRole));
|
||||
}
|
||||
IdentityUser user = await userManager.FindByEmailAsync(UserEmail);
|
||||
IdentityUser? user = await userManager.FindByEmailAsync(UserEmail);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@
|
|||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5</UserSecretsId>
|
||||
|
||||
<!--remove the elements below after GA release-->
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -25,9 +29,14 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<RuntimeHostConfigurationOption
|
||||
Include="System.Net.SocketsHttpHandler.Http3Support"
|
||||
Value="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="wwwroot\favicon.ico">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -38,6 +38,12 @@ else
|
|||
// if you are using SQLite default is ..\Northwind.db
|
||||
builder.Services.AddNorthwindContext();
|
||||
|
||||
builder.Services.AddOutputCache(options =>
|
||||
{
|
||||
options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(20);
|
||||
options.AddPolicy("views", p => p.VaryByQuery(""));
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient(name: "Northwind.WebApi",
|
||||
configureClient: options =>
|
||||
{
|
||||
|
|
@ -77,16 +83,23 @@ else
|
|||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseOutputCache();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}")
|
||||
.CacheOutput("views");
|
||||
|
||||
app.MapRazorPages();
|
||||
|
||||
app.MapGet("/notcached", () => DateTime.Now.ToString());
|
||||
|
||||
app.MapGet("/cached", () => DateTime.Now.ToString()).CacheOutput();
|
||||
|
||||
// Section 4 - start the host web server listening for HTTP requests
|
||||
app.Run();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,16 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.Mvc": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
ViewData["Title"] = "Product Detail - " + Model.ProductName;
|
||||
}
|
||||
<h2>Product Detail</h2>
|
||||
<p class="alert alert-@ViewData["alertstyle"]">
|
||||
@DateTime.Now.ToLongTimeString()</p>
|
||||
<hr />
|
||||
<div>
|
||||
<dl class="dl-horizontal">
|
||||
|
|
@ -10,8 +12,8 @@
|
|||
<dd>@Model.ProductId</dd>
|
||||
<dt>Product Name</dt>
|
||||
<dd>@Model.ProductName</dd>
|
||||
<dt>Category Id</dt>
|
||||
<dd>@Model.CategoryId</dd>
|
||||
<dt>Category</dt>
|
||||
<dd>@Model.CategoryId - @Model.Category.CategoryName</dd>
|
||||
<dt>Unit Price</dt>
|
||||
<dd>@Model.UnitPrice.Value.ToString("C")</dd>
|
||||
<dt>Units In Stock</dt>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.OutputCaching": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -10,6 +10,10 @@
|
|||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Console" Static="true" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -7,6 +7,9 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddNorthwindContext();
|
||||
|
||||
builder.Services.AddRequestDecompression();
|
||||
|
||||
/*
|
||||
builder.WebHost.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.ListenAnyIP(5001, listenOptions =>
|
||||
|
|
@ -15,6 +18,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
|
|||
listenOptions.UseHttps(); // HTTP/3 requires secure connections
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
@ -51,6 +55,8 @@ app.Use(async (HttpContext context, Func<Task> next) =>
|
|||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRequestDecompression();
|
||||
|
||||
app.UseDefaultFiles(); // index.html, default.html, and so on
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,16 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.Web": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
|
|
|
|||
BIN
vs4win/PracticalApps/Northwind.Web/wwwroot/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -14,6 +14,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0-*" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -38,8 +38,11 @@ builder.Services.AddSwaggerGen();
|
|||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddDbContextCheck<NorthwindContext>();
|
||||
.AddDbContextCheck<NorthwindContext>()
|
||||
// execute SELECT 1 using the specified connection string
|
||||
.AddSqlServer("Data Source=.;Initial Catalog=Northwind;Integrated Security=true;");
|
||||
|
||||
/*
|
||||
builder.WebHost.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.ListenAnyIP(5002, listenOptions =>
|
||||
|
|
@ -48,6 +51,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
|
|||
listenOptions.UseHttps(); // HTTP/3 requires secure connections
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,20 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.WebApi": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5002",
|
||||
"environmentVariables": {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
vs4win/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
vs4win/PracticalApps/favicon_io.zip
Normal file
|
|
@ -10,4 +10,9 @@
|
|||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- change Sqlite to SqlServer if you prefer -->
|
||||
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -9,11 +9,21 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Minimal.WebApi": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5003",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
|
|
|||
BIN
vscode/PracticalApps/Minimal.WebApi/wwwroot/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -6,6 +6,14 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="wwwroot\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- change Sqlite to SqlServer if you prefer -->
|
||||
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -8,7 +8,16 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.BlazorServer": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5004",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -8,11 +8,19 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.BlazorWasm.Server": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5006",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||
"applicationUrl": "https://localhost:5007;http://localhost:5006",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
|
@ -27,4 +35,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -75,14 +75,16 @@ namespace Northwind.Mvc.Controllers
|
|||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> ProductDetail(int? id)
|
||||
public async Task<IActionResult> ProductDetail(int? id, string alertstyle = "success")
|
||||
{
|
||||
ViewData["alertstyle"] = alertstyle;
|
||||
|
||||
if (!id.HasValue)
|
||||
{
|
||||
return BadRequest("You must pass a product ID in the route, for example, /Home/ProductDetail/21");
|
||||
}
|
||||
|
||||
Product? model = await db.Products
|
||||
Product? model = await db.Products.Include(p => p.Category)
|
||||
.SingleOrDefaultAsync(p => p.ProductId == id);
|
||||
|
||||
if (model is null)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class RolesController : Controller
|
|||
{
|
||||
await roleManager.CreateAsync(new IdentityRole(AdminRole));
|
||||
}
|
||||
IdentityUser user = await userManager.FindByEmailAsync(UserEmail);
|
||||
IdentityUser? user = await userManager.FindByEmailAsync(UserEmail);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@
|
|||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>aspnet-Northwind.Mvc-32868776-9AE7-4BFC-8CB8-DFDC975ABEA5</UserSecretsId>
|
||||
|
||||
<!--remove the elements below after GA release-->
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -25,9 +29,14 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<RuntimeHostConfigurationOption
|
||||
Include="System.Net.SocketsHttpHandler.Http3Support"
|
||||
Value="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="wwwroot\favicon.ico">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -38,6 +38,12 @@ else
|
|||
// if you are using SQLite default is ..\Northwind.db
|
||||
builder.Services.AddNorthwindContext();
|
||||
|
||||
builder.Services.AddOutputCache(options =>
|
||||
{
|
||||
options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(20);
|
||||
options.AddPolicy("views", p => p.VaryByQuery(""));
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient(name: "Northwind.WebApi",
|
||||
configureClient: options =>
|
||||
{
|
||||
|
|
@ -77,16 +83,23 @@ else
|
|||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseOutputCache();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}")
|
||||
.CacheOutput("views");
|
||||
|
||||
app.MapRazorPages();
|
||||
|
||||
app.MapGet("/notcached", () => DateTime.Now.ToString());
|
||||
|
||||
app.MapGet("/cached", () => DateTime.Now.ToString()).CacheOutput();
|
||||
|
||||
// Section 4 - start the host web server listening for HTTP requests
|
||||
app.Run();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,16 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.Mvc": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
ViewData["Title"] = "Product Detail - " + Model.ProductName;
|
||||
}
|
||||
<h2>Product Detail</h2>
|
||||
<p class="alert alert-@ViewData["alertstyle"]">
|
||||
@DateTime.Now.ToLongTimeString()</p>
|
||||
<hr />
|
||||
<div>
|
||||
<dl class="dl-horizontal">
|
||||
|
|
@ -10,8 +12,8 @@
|
|||
<dd>@Model.ProductId</dd>
|
||||
<dt>Product Name</dt>
|
||||
<dd>@Model.ProductName</dd>
|
||||
<dt>Category Id</dt>
|
||||
<dd>@Model.CategoryId</dd>
|
||||
<dt>Category</dt>
|
||||
<dd>@Model.CategoryId - @Model.Category.CategoryName</dd>
|
||||
<dt>Unit Price</dt>
|
||||
<dd>@Model.UnitPrice.Value.ToString("C")</dd>
|
||||
<dt>Units In Stock</dt>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.OutputCaching": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -10,6 +10,10 @@
|
|||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Console" Static="true" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -7,6 +7,9 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddNorthwindContext();
|
||||
|
||||
builder.Services.AddRequestDecompression();
|
||||
|
||||
/*
|
||||
builder.WebHost.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.ListenAnyIP(5001, listenOptions =>
|
||||
|
|
@ -15,6 +18,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
|
|||
listenOptions.UseHttps(); // HTTP/3 requires secure connections
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
@ -51,6 +55,8 @@ app.Use(async (HttpContext context, Func<Task> next) =>
|
|||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRequestDecompression();
|
||||
|
||||
app.UseDefaultFiles(); // index.html, default.html, and so on
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,16 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.Web": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
|
|
|
|||
BIN
vscode/PracticalApps/Northwind.Web/wwwroot/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -14,6 +14,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0-*" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -38,8 +38,11 @@ builder.Services.AddSwaggerGen();
|
|||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddDbContextCheck<NorthwindContext>();
|
||||
.AddDbContextCheck<NorthwindContext>()
|
||||
// execute SELECT 1 using the specified connection string
|
||||
.AddSqlServer("Data Source=.;Initial Catalog=Northwind;Integrated Security=true;");
|
||||
|
||||
/*
|
||||
builder.WebHost.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.ListenAnyIP(5002, listenOptions =>
|
||||
|
|
@ -48,6 +51,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
|
|||
listenOptions.UseHttps(); // HTTP/3 requires secure connections
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,20 @@
|
|||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.WebApi": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5002",
|
||||
"environmentVariables": {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
vscode/PracticalApps/Northwind.WebApi/wwwroot/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |