diff --git a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ReportLogic.cs b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ReportLogic.cs index 8417e2c..6e5e9c1 100644 --- a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/ReportLogic.cs @@ -43,8 +43,6 @@ namespace FoodOrdersBusinessLogic.BusinessLogics /// public List GetDishComponent() { - var components = _componentStorage.GetFullList(); - var dishes = _dishStorage.GetFullList(); var list = new List(); diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Implements/DishStorage.cs b/FoodOrders/FoodOrdersDatabaseImplement/Implements/DishStorage.cs index 1c3e474..82b8da8 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Implements/DishStorage.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Implements/DishStorage.cs @@ -93,7 +93,8 @@ namespace FoodOrdersDatabaseImplement.Implements using var context = new FoodOrdersDatabase(); var element = context.Dishes .Include(x => x.Components) - .FirstOrDefault(rec => rec.Id == model.Id); + .Include(x => x.Orders) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Dishes.Remove(element); diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.Designer.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.Designer.cs new file mode 100644 index 0000000..2fcc6f2 --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.Designer.cs @@ -0,0 +1,171 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DishName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Dishes"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DishId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DishId"); + + b.ToTable("DishComponents"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("DishId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("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 + } + } +} diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.cs new file mode 100644 index 0000000..c5bb3b4 --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230330090832_new.cs @@ -0,0 +1,125 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FoodOrdersDatabaseImplement.Migrations +{ + /// + public partial class @new : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Dishes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DishName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Dishes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "DishComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DishId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DishId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DishComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Dishes"); + } + } +} diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs index 62ce615..b9d5329 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs @@ -39,7 +39,7 @@ namespace FoodOrdersDatabaseImplement.Migrations b.HasKey("Id"); - b.ToTable("Components"); + b.ToTable("Components", (string)null); }); modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b => @@ -59,7 +59,7 @@ namespace FoodOrdersDatabaseImplement.Migrations b.HasKey("Id"); - b.ToTable("Dishes"); + b.ToTable("Dishes", (string)null); }); modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b => @@ -85,7 +85,7 @@ namespace FoodOrdersDatabaseImplement.Migrations b.HasIndex("DishId"); - b.ToTable("DishComponents"); + b.ToTable("DishComponents", (string)null); }); modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => @@ -118,7 +118,7 @@ namespace FoodOrdersDatabaseImplement.Migrations b.HasIndex("DishId"); - b.ToTable("Orders"); + b.ToTable("Orders", (string)null); }); modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b => @@ -196,7 +196,7 @@ namespace FoodOrdersDatabaseImplement.Migrations modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => { b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish") - .WithMany() + .WithMany("Orders") .HasForeignKey("DishId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -231,6 +231,8 @@ namespace FoodOrdersDatabaseImplement.Migrations modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b => { b.Navigation("Components"); + + b.Navigation("Orders"); }); modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b => diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Models/Dish.cs b/FoodOrders/FoodOrdersDatabaseImplement/Models/Dish.cs index 43eadf7..f6bb534 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Models/Dish.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Models/Dish.cs @@ -35,6 +35,9 @@ namespace FoodOrdersDatabaseImplement.Models [ForeignKey("DishId")] public virtual List Components { get; set; } = new(); + [ForeignKey("DishId")] + public virtual List Orders { get; set; } = new(); + public static Dish Create(FoodOrdersDatabase context, DishBindingModel model) { return new Dish()