Merge branch 'BaseLabWork03' into BaseLabWork04
This commit is contained in:
commit
967b102200
@ -93,7 +93,8 @@ namespace FoodOrdersDatabaseImplement.Implements
|
|||||||
using var context = new FoodOrdersDatabase();
|
using var context = new FoodOrdersDatabase();
|
||||||
var element = context.Dishes
|
var element = context.Dishes
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Components)
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.Include(x => x.Orders)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Dishes.Remove(element);
|
context.Dishes.Remove(element);
|
||||||
|
171
FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.Designer.cs
generated
Normal file
171
FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FoodOrdersDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FoodOrdersDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(FoodOrdersDatabase))]
|
||||||
|
[Migration("20230330090832_new")]
|
||||||
|
partial class @new
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("DishName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Dishes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("DishId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("DishId");
|
||||||
|
|
||||||
|
b.ToTable("DishComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("DishId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("DishId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FoodOrdersDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("DishComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("DishId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Dish");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("DishId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Dish");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("DishComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FoodOrdersDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class @new : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Components",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Cost = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Components", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Dishes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DishName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Dishes", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "DishComponents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DishId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_DishComponents", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_DishComponents_Components_ComponentId",
|
||||||
|
column: x => x.ComponentId,
|
||||||
|
principalTable: "Components",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_DishComponents_Dishes_DishId",
|
||||||
|
column: x => x.DishId,
|
||||||
|
principalTable: "Dishes",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DishId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Sum = table.Column<double>(type: "float", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "int", nullable: false),
|
||||||
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_Dishes_DishId",
|
||||||
|
column: x => x.DishId,
|
||||||
|
principalTable: "Dishes",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_DishComponents_ComponentId",
|
||||||
|
table: "DishComponents",
|
||||||
|
column: "ComponentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_DishComponents_DishId",
|
||||||
|
table: "DishComponents",
|
||||||
|
column: "DishId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_DishId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "DishId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "DishComponents");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Components");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Dishes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -39,7 +39,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Components");
|
b.ToTable("Components", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
||||||
@ -59,7 +59,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Dishes");
|
b.ToTable("Dishes", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
||||||
@ -85,7 +85,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("DishId");
|
b.HasIndex("DishId");
|
||||||
|
|
||||||
b.ToTable("DishComponents");
|
b.ToTable("DishComponents", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
||||||
@ -118,7 +118,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("DishId");
|
b.HasIndex("DishId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
||||||
@ -143,7 +143,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
|
|||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
||||||
.WithMany()
|
.WithMany("Orders")
|
||||||
.HasForeignKey("DishId")
|
.HasForeignKey("DishId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
@ -159,6 +159,8 @@ namespace FoodOrdersDatabaseImplement.Migrations
|
|||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Components");
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,9 @@ namespace FoodOrdersDatabaseImplement.Models
|
|||||||
[ForeignKey("DishId")]
|
[ForeignKey("DishId")]
|
||||||
public virtual List<DishComponent> Components { get; set; } = new();
|
public virtual List<DishComponent> Components { get; set; } = new();
|
||||||
|
|
||||||
|
[ForeignKey("DishId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
|
||||||
public static Dish Create(FoodOrdersDatabase context, DishBindingModel model)
|
public static Dish Create(FoodOrdersDatabase context, DishBindingModel model)
|
||||||
{
|
{
|
||||||
return new Dish()
|
return new Dish()
|
||||||
|
Loading…
Reference in New Issue
Block a user