diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230308222141_InitMigration.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326151327_InitialCreate.Designer.cs similarity index 95% rename from Pizzeria/PizzeriaDatabaseImplement/Migrations/20230308222141_InitMigration.Designer.cs rename to Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326151327_InitialCreate.Designer.cs index 05251d8..bc10304 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230308222141_InitMigration.Designer.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326151327_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using PizzeriaDatabaseImplement; namespace PizzeriaDatabaseImplement.Migrations { [DbContext(typeof(PizzeriaDatabase))] - [Migration("20230308222141_InitMigration")] - partial class InitMigration + [Migration("20230326151327_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -115,9 +115,6 @@ namespace PizzeriaDatabaseImplement.Migrations b.Property("PizzaId") .HasColumnType("int"); - b.Property("ProductId") - .HasColumnType("int"); - b.HasKey("Id"); b.HasIndex("ComponentId"); @@ -146,7 +143,7 @@ namespace PizzeriaDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Product") + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") .WithMany("Components") .HasForeignKey("PizzaId") .OnDelete(DeleteBehavior.Cascade) @@ -154,7 +151,7 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("Component"); - b.Navigation("Product"); + b.Navigation("Pizza"); }); modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230308222141_InitMigration.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326151327_InitialCreate.cs similarity index 96% rename from Pizzeria/PizzeriaDatabaseImplement/Migrations/20230308222141_InitMigration.cs rename to Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326151327_InitialCreate.cs index 27c2c27..ad96fd6 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230308222141_InitMigration.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326151327_InitialCreate.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace PizzeriaDatabaseImplement.Migrations { /// - public partial class InitMigration : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -69,10 +69,9 @@ namespace PizzeriaDatabaseImplement.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - ProductId = table.Column(type: "int", nullable: false), + PizzaId = table.Column(type: "int", nullable: false), ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - PizzaId = table.Column(type: "int", nullable: false) + Count = table.Column(type: "int", nullable: false) }, constraints: table => { diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs index 3a1a691..b5035a2 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs @@ -112,9 +112,6 @@ namespace PizzeriaDatabaseImplement.Migrations b.Property("PizzaId") .HasColumnType("int"); - b.Property("ProductId") - .HasColumnType("int"); - b.HasKey("Id"); b.HasIndex("ComponentId"); @@ -143,7 +140,7 @@ namespace PizzeriaDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Product") + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") .WithMany("Components") .HasForeignKey("PizzaId") .OnDelete(DeleteBehavior.Cascade) @@ -151,7 +148,7 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("Component"); - b.Navigation("Product"); + b.Navigation("Pizza"); }); modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs index a32f628..0bb2059 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs @@ -61,7 +61,7 @@ namespace PizzeriaDatabaseImplement.Models }; public void UpdateComponents(PizzeriaDatabase context, PizzaBindingModel model) { - var pizzaComponents = context.PizzaComponents.Where(rec => rec.ProductId == model.Id).ToList(); + var pizzaComponents = context.PizzaComponents.Where(rec => rec.PizzaId == model.Id).ToList(); if (pizzaComponents != null && pizzaComponents.Count > 0) { context.PizzaComponents.RemoveRange(pizzaComponents.Where(rec => !model.PizzaComponents.ContainsKey(rec.ComponentId))); @@ -74,11 +74,11 @@ namespace PizzeriaDatabaseImplement.Models context.SaveChanges(); } - var product = context.Pizzas.First(x => x.Id == Id); + var pizza = context.Pizzas.First(x => x.Id == Id); foreach (var pc in model.PizzaComponents) { context.PizzaComponents.Add(new PizzaComponent { - Product = product, + Pizza = pizza, Component = context.Components.First(x => x.Id == pc.Key), Count = pc.Value.Item2 }); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs index 35fb5aa..a5a83e3 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs @@ -11,12 +11,12 @@ namespace PizzeriaDatabaseImplement.Models { public int Id { get; set; } [Required] - public int ProductId { get; set; } + public int PizzaId { get; set; } [Required] public int ComponentId { get; set; } [Required] public int Count { get; set; } public virtual Component Component { get; set; } = new(); - public virtual Pizza Product { get; set; } = new(); + public virtual Pizza Pizza { get; set; } = new(); } } diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj index 738b64b..2b00238 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + +