-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (42 loc) · 1.48 KB
/
Copy pathProgram.cs
File metadata and controls
55 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Microsoft.EntityFrameworkCore;
using SportsStore.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<StoreDBContext>(opts => {
opts.UseSqlServer(
builder.Configuration["ConnectionStrings:SportsStoreConnection"]);
});
builder.Services.AddScoped<IStoreRepository, EFStoreRepository>();
builder.Services.AddRazorPages();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession();
var app = builder.Build();
// Serve static files
app.UseStaticFiles();
app.UseSession();
// Route for category with page
app.MapControllerRoute(
name: "catpage",
pattern: "{category}/Page{productPage:int}",
defaults: new { Controller = "Home", action = "Index" });
// Route for just page
app.MapControllerRoute(
name: "page",
pattern: "Page{productPage:int}",
defaults: new { Controller = "Home", action = "Index", productPage = 1 });
// Route for just category
app.MapControllerRoute(
name: "category",
pattern: "{category}",
defaults: new { Controller = "Home", action = "Index", productPage = 1 });
// Fallback route
app.MapControllerRoute(
name: "pagination",
pattern: "Products/Page{productPage}",
defaults: new { Controller = "Home", action = "Index", productPage = 1 });
// Default route
app.MapDefaultControllerRoute();
app.MapRazorPages();
// Seed database
SeedData.EnsurePopulated(app);
app.Run();