Filler-Tabelle hinzugefügt

This commit is contained in:
BuildTools 2024-02-05 17:58:14 +01:00
parent e94064cff2
commit 531c833e76
7 changed files with 724 additions and 4 deletions

View File

@ -9,6 +9,8 @@ namespace CocktailWeb.Data
public DbSet<Flasche> Flaschen { get; set; }
public DbSet<CocktailFlasche> CocktailFlaschen { get; set; }
public DbSet<Cocktail> Cocktails { get; set; }
public DbSet<Filler> Fillers { get; set; }
public DbDataContext(IConfiguration configuration)
{
_configuration = configuration;
@ -27,6 +29,22 @@ namespace CocktailWeb.Data
new Flasche("Wodka") { Id = 2 }
);
modelBuilder.Entity<Filler>().HasData(
new Filler() { Id = 1, Pos = 1, Type = Filler.FillerType.Pump },
new Filler() { Id = 2, Pos = 2, Type = Filler.FillerType.Pump },
new Filler() { Id = 3, Pos = 3, Type = Filler.FillerType.Pump },
new Filler() { Id = 4, Pos = 4, Type = Filler.FillerType.Pourer },
new Filler() { Id = 5, Pos = 5, Type = Filler.FillerType.Pourer },
new Filler() { Id = 6, Pos = 6, Type = Filler.FillerType.Pourer },
new Filler() { Id = 7, Pos = 7, Type = Filler.FillerType.Pourer },
new Filler() { Id = 8, Pos = 8, Type = Filler.FillerType.Pourer },
new Filler() { Id = 9, Pos = 9, Type = Filler.FillerType.Pourer },
new Filler() { Id = 10, Pos = 10, Type = Filler.FillerType.Pourer },
new Filler() { Id = 11, Pos = 11, Type = Filler.FillerType.Pourer },
new Filler() { Id = 12, Pos = 12, Type = Filler.FillerType.Pump },
new Filler() { Id = 13, Pos = 13, Type = Filler.FillerType.Pump },
new Filler() { Id = 14, Pos = 14, Type = Filler.FillerType.Pump }
);
// modelBuilder.Entity<Cocktail>().HasMany(c => c.CocktailFlaschen).WithOne(c => c.Cocktail).HasForeignKey(c => c.CocktailID);

View File

@ -0,0 +1,17 @@
namespace CocktailWeb.Data
{
public class Filler
{
public int Id { get; set; }
public int Pos { get; set; }
public FillerType Type { get; set; }
public Flasche? Flasche { get; set; }
public enum FillerType
{
Pump,
Pourer
}
}
}

View File

@ -0,0 +1,152 @@
// <auto-generated />
using System;
using CocktailWeb.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CocktailWeb.Migrations
{
[DbContext(typeof(DbDataContext))]
[Migration("20240131184613_CreateFillerTable")]
partial class CreateFillerTable
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("CocktailWeb.Data.Cocktail", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ImageURL")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Cocktails");
});
modelBuilder.Entity("CocktailWeb.Data.CocktailFlasche", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CocktailID")
.HasColumnType("INTEGER");
b.Property<int>("FlascheID")
.HasColumnType("INTEGER");
b.Property<int>("Menge")
.HasColumnType("INTEGER");
b.Property<int>("Reihenfolge")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("CocktailID");
b.HasIndex("FlascheID");
b.ToTable("CocktailFlaschen");
});
modelBuilder.Entity("CocktailWeb.Data.Filler", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("FlascheId")
.HasColumnType("INTEGER");
b.Property<int>("Pos")
.HasColumnType("INTEGER");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("FlascheId");
b.ToTable("Fillers");
});
modelBuilder.Entity("CocktailWeb.Data.Flasche", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Flaschen", (string)null);
b.HasData(
new
{
Id = 1,
Name = "Jägermeister"
},
new
{
Id = 2,
Name = "Wodka"
});
});
modelBuilder.Entity("CocktailWeb.Data.CocktailFlasche", b =>
{
b.HasOne("CocktailWeb.Data.Cocktail", "Cocktail")
.WithMany("Cocktailflaschen")
.HasForeignKey("CocktailID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CocktailWeb.Data.Flasche", "Flasche")
.WithMany()
.HasForeignKey("FlascheID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cocktail");
b.Navigation("Flasche");
});
modelBuilder.Entity("CocktailWeb.Data.Filler", b =>
{
b.HasOne("CocktailWeb.Data.Flasche", "Flasche")
.WithMany()
.HasForeignKey("FlascheId");
b.Navigation("Flasche");
});
modelBuilder.Entity("CocktailWeb.Data.Cocktail", b =>
{
b.Navigation("Cocktailflaschen");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CocktailWeb.Migrations
{
/// <inheritdoc />
public partial class CreateFillerTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Pos",
table: "Flaschen");
migrationBuilder.CreateTable(
name: "Fillers",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pos = table.Column<int>(type: "INTEGER", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
FlascheId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Fillers", x => x.Id);
table.ForeignKey(
name: "FK_Fillers_Flaschen_FlascheId",
column: x => x.FlascheId,
principalTable: "Flaschen",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Fillers_FlascheId",
table: "Fillers",
column: "FlascheId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Fillers");
migrationBuilder.AddColumn<int>(
name: "Pos",
table: "Flaschen",
type: "INTEGER",
nullable: true);
migrationBuilder.UpdateData(
table: "Flaschen",
keyColumn: "Id",
keyValue: 1,
column: "Pos",
value: null);
migrationBuilder.UpdateData(
table: "Flaschen",
keyColumn: "Id",
keyValue: 2,
column: "Pos",
value: null);
}
}
}

View File

@ -0,0 +1,238 @@
// <auto-generated />
using System;
using CocktailWeb.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CocktailWeb.Migrations
{
[DbContext(typeof(DbDataContext))]
[Migration("20240205165625_SeedDataFillers")]
partial class SeedDataFillers
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("CocktailWeb.Data.Cocktail", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ImageURL")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Cocktails");
});
modelBuilder.Entity("CocktailWeb.Data.CocktailFlasche", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CocktailID")
.HasColumnType("INTEGER");
b.Property<int>("FlascheID")
.HasColumnType("INTEGER");
b.Property<int>("Menge")
.HasColumnType("INTEGER");
b.Property<int>("Reihenfolge")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("CocktailID");
b.HasIndex("FlascheID");
b.ToTable("CocktailFlaschen");
});
modelBuilder.Entity("CocktailWeb.Data.Filler", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("FlascheId")
.HasColumnType("INTEGER");
b.Property<int>("Pos")
.HasColumnType("INTEGER");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("FlascheId");
b.ToTable("Fillers");
b.HasData(
new
{
Id = 1,
Pos = 1,
Type = 0
},
new
{
Id = 2,
Pos = 2,
Type = 0
},
new
{
Id = 3,
Pos = 3,
Type = 0
},
new
{
Id = 4,
Pos = 4,
Type = 1
},
new
{
Id = 5,
Pos = 5,
Type = 1
},
new
{
Id = 6,
Pos = 6,
Type = 1
},
new
{
Id = 7,
Pos = 7,
Type = 1
},
new
{
Id = 8,
Pos = 8,
Type = 1
},
new
{
Id = 9,
Pos = 9,
Type = 1
},
new
{
Id = 10,
Pos = 10,
Type = 1
},
new
{
Id = 11,
Pos = 11,
Type = 1
},
new
{
Id = 12,
Pos = 12,
Type = 0
},
new
{
Id = 13,
Pos = 13,
Type = 0
},
new
{
Id = 14,
Pos = 14,
Type = 0
});
});
modelBuilder.Entity("CocktailWeb.Data.Flasche", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Flaschen", (string)null);
b.HasData(
new
{
Id = 1,
Name = "Jägermeister"
},
new
{
Id = 2,
Name = "Wodka"
});
});
modelBuilder.Entity("CocktailWeb.Data.CocktailFlasche", b =>
{
b.HasOne("CocktailWeb.Data.Cocktail", "Cocktail")
.WithMany("Cocktailflaschen")
.HasForeignKey("CocktailID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CocktailWeb.Data.Flasche", "Flasche")
.WithMany()
.HasForeignKey("FlascheID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cocktail");
b.Navigation("Flasche");
});
modelBuilder.Entity("CocktailWeb.Data.Filler", b =>
{
b.HasOne("CocktailWeb.Data.Flasche", "Flasche")
.WithMany()
.HasForeignKey("FlascheId");
b.Navigation("Flasche");
});
modelBuilder.Entity("CocktailWeb.Data.Cocktail", b =>
{
b.Navigation("Cocktailflaschen");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,111 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace CocktailWeb.Migrations
{
/// <inheritdoc />
public partial class SeedDataFillers : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "Fillers",
columns: new[] { "Id", "FlascheId", "Pos", "Type" },
values: new object[,]
{
{ 1, null, 1, 0 },
{ 2, null, 2, 0 },
{ 3, null, 3, 0 },
{ 4, null, 4, 1 },
{ 5, null, 5, 1 },
{ 6, null, 6, 1 },
{ 7, null, 7, 1 },
{ 8, null, 8, 1 },
{ 9, null, 9, 1 },
{ 10, null, 10, 1 },
{ 11, null, 11, 1 },
{ 12, null, 12, 0 },
{ 13, null, 13, 0 },
{ 14, null, 14, 0 }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 3);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 4);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 5);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 6);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 7);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 8);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 9);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 10);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 11);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 12);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 13);
migrationBuilder.DeleteData(
table: "Fillers",
keyColumn: "Id",
keyValue: 14);
}
}
}

View File

@ -15,7 +15,7 @@ namespace CocktailWeb.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.14");
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("CocktailWeb.Data.Cocktail", b =>
{
@ -62,6 +62,114 @@ namespace CocktailWeb.Migrations
b.ToTable("CocktailFlaschen");
});
modelBuilder.Entity("CocktailWeb.Data.Filler", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("FlascheId")
.HasColumnType("INTEGER");
b.Property<int>("Pos")
.HasColumnType("INTEGER");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("FlascheId");
b.ToTable("Fillers");
b.HasData(
new
{
Id = 1,
Pos = 1,
Type = 0
},
new
{
Id = 2,
Pos = 2,
Type = 0
},
new
{
Id = 3,
Pos = 3,
Type = 0
},
new
{
Id = 4,
Pos = 4,
Type = 1
},
new
{
Id = 5,
Pos = 5,
Type = 1
},
new
{
Id = 6,
Pos = 6,
Type = 1
},
new
{
Id = 7,
Pos = 7,
Type = 1
},
new
{
Id = 8,
Pos = 8,
Type = 1
},
new
{
Id = 9,
Pos = 9,
Type = 1
},
new
{
Id = 10,
Pos = 10,
Type = 1
},
new
{
Id = 11,
Pos = 11,
Type = 1
},
new
{
Id = 12,
Pos = 12,
Type = 0
},
new
{
Id = 13,
Pos = 13,
Type = 0
},
new
{
Id = 14,
Pos = 14,
Type = 0
});
});
modelBuilder.Entity("CocktailWeb.Data.Flasche", b =>
{
b.Property<int>("Id")
@ -72,9 +180,6 @@ namespace CocktailWeb.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("Pos")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Flaschen", (string)null);
@ -111,6 +216,15 @@ namespace CocktailWeb.Migrations
b.Navigation("Flasche");
});
modelBuilder.Entity("CocktailWeb.Data.Filler", b =>
{
b.HasOne("CocktailWeb.Data.Flasche", "Flasche")
.WithMany()
.HasForeignKey("FlascheId");
b.Navigation("Flasche");
});
modelBuilder.Entity("CocktailWeb.Data.Cocktail", b =>
{
b.Navigation("Cocktailflaschen");