diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Implements/ShopStorage.cs b/FoodOrders/FoodOrdersDatabaseImplement/Implements/ShopStorage.cs index b2e28ad..f9352d5 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Implements/ShopStorage.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Implements/ShopStorage.cs @@ -127,10 +127,10 @@ namespace FoodOrdersDatabaseImplement.Implements foreach (var shopDish in ListShopDish) { - if (count - shopDish.Count >= 0) + if (count - shopDish.Count > 0) { count -= shopDish.Count; - ListShopDish.Remove(shopDish); + shopDish.Count = 0; } else { diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230323201720_HardLabWork03.Designer.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230323201720_HardLabWork03.Designer.cs new file mode 100644 index 0000000..00d1b34 --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230323201720_HardLabWork03.Designer.cs @@ -0,0 +1,246 @@ +// +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("20230323201720_HardLabWork03")] + partial class HardLabWork03 + { + /// + 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.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Capacity") + .HasColumnType("int"); + + b.Property("DateOfOpening") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.ShopDish", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DishId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DishId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopDishes"); + }); + + 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() + .HasForeignKey("DishId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Dish"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.ShopDish", b => + { + b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish") + .WithMany() + .HasForeignKey("DishId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FoodOrdersDatabaseImplement.Models.Shop", "Shop") + .WithMany("Dishes") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Dish"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => + { + b.Navigation("DishComponents"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b => + { + b.Navigation("Dishes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230323201720_HardLabWork03.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230323201720_HardLabWork03.cs new file mode 100644 index 0000000..549bc46 --- /dev/null +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/20230323201720_HardLabWork03.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FoodOrdersDatabaseImplement.Migrations +{ + /// + public partial class HardLabWork03 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOfOpening = table.Column(type: "datetime2", nullable: false), + Capacity = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ShopDishes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopId = table.Column(type: "int", nullable: false), + DishId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopDishes", x => x.Id); + table.ForeignKey( + name: "FK_ShopDishes_Dishes_DishId", + column: x => x.DishId, + principalTable: "Dishes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopDishes_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShopDishes_DishId", + table: "ShopDishes", + column: "DishId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopDishes_ShopId", + table: "ShopDishes", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ShopDishes"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs index 6d911c5..b0a39c1 100644 --- a/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs +++ b/FoodOrders/FoodOrdersDatabaseImplement/Migrations/FoodOrdersDatabaseModelSnapshot.cs @@ -121,6 +121,59 @@ namespace FoodOrdersDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Capacity") + .HasColumnType("int"); + + b.Property("DateOfOpening") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.ShopDish", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DishId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DishId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopDishes"); + }); + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b => { b.HasOne("FoodOrdersDatabaseImplement.Models.Component", "Component") @@ -151,6 +204,25 @@ namespace FoodOrdersDatabaseImplement.Migrations b.Navigation("Dish"); }); + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.ShopDish", b => + { + b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish") + .WithMany() + .HasForeignKey("DishId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FoodOrdersDatabaseImplement.Models.Shop", "Shop") + .WithMany("Dishes") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Dish"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => { b.Navigation("DishComponents"); @@ -160,6 +232,11 @@ namespace FoodOrdersDatabaseImplement.Migrations { b.Navigation("Components"); }); + + modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Shop", b => + { + b.Navigation("Dishes"); + }); #pragma warning restore 612, 618 } }