Compare commits
13 Commits
0.1.2
...
f41b2ae005
| Author | SHA1 | Date | |
|---|---|---|---|
| f41b2ae005 | |||
| 64fa9e1823 | |||
| cf175649a0 | |||
| bc3a05ebf9 | |||
| e5a6e81881 | |||
| c8e5c403fb | |||
| 07044d6156 | |||
| 366fad3241 | |||
| 0eecf829e1 | |||
| e04b85fa30 | |||
| 6dcdbea46b | |||
| c69cc287b6 | |||
| d258ea4615 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -54,3 +54,4 @@ TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
.vs/
|
||||
pizza.db*
|
||||
@@ -18,14 +18,6 @@ namespace PizzaExpress.Data
|
||||
public static void Initialize(PizzaContext ctx)
|
||||
{
|
||||
if (ctx.Pizze.Any()) return;
|
||||
|
||||
ctx.Pizze.AddRange(
|
||||
new Pizza { Id = 1, Nome = "Margherita", Prezzo = 4.50m },
|
||||
new Pizza { Id = 2, Nome = "Prosciutto", Prezzo = 5.00m },
|
||||
new Pizza { Id = 3, Nome = "Capricciosa", Prezzo = 7.00m }
|
||||
);
|
||||
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
public int Id { get; set; }
|
||||
public string Nome { get; set; } = string.Empty;
|
||||
public decimal Prezzo { get; set; }
|
||||
public string Note { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.11" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>http</ActiveDebugProfile>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
|
||||
@@ -30,9 +30,10 @@ namespace PizzaExpress
|
||||
builder.Services.AddControllers()
|
||||
.AddXmlSerializerFormatters();
|
||||
|
||||
// DB in memory perch<63> siamo froci
|
||||
// Creazione del contesto con DB SQLite
|
||||
builder.Services.AddDbContext<PizzaContext>(opt =>
|
||||
opt.UseInMemoryDatabase("dbpizze"));
|
||||
opt.UseSqlite("Data Source=pizza.db"));
|
||||
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@@ -40,9 +41,11 @@ namespace PizzaExpress
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
using (var porcoidddioooo = app.Services.CreateScope())
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var ctx = porcoidddioooo.ServiceProvider.GetRequiredService<PizzaContext>();
|
||||
var ctx = scope.ServiceProvider.GetRequiredService<PizzaContext>();
|
||||
// Crea il DB e le tabelle basate sul modello se non esistono (no migrations)
|
||||
ctx.Database.EnsureCreated();
|
||||
SeedData.Initialize(ctx);
|
||||
}
|
||||
|
||||
@@ -56,6 +59,8 @@ namespace PizzaExpress
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
PizzaExpress/pizza.example.db
Normal file
BIN
PizzaExpress/pizza.example.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user