13 Commits
0.1.2 ... main

7 changed files with 16 additions and 17 deletions

1
.gitignore vendored
View File

@@ -54,3 +54,4 @@ TestResult.xml
nunit-*.xml
.vs/
pizza.db*

View File

@@ -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();
}
}
}

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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();
}
}

Binary file not shown.