Rename products

This commit is contained in:
shadowik 2023-03-26 19:15:52 +04:00
parent 8cde12c752
commit fc252a5ea4
6 changed files with 18 additions and 21 deletions

View File

@ -12,8 +12,8 @@ using PizzeriaDatabaseImplement;
namespace PizzeriaDatabaseImplement.Migrations
{
[DbContext(typeof(PizzeriaDatabase))]
[Migration("20230308222141_InitMigration")]
partial class InitMigration
[Migration("20230326151327_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -115,9 +115,6 @@ namespace PizzeriaDatabaseImplement.Migrations
b.Property<int>("PizzaId")
.HasColumnType("int");
b.Property<int>("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 =>

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace PizzeriaDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitMigration : Migration
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -69,10 +69,9 @@ namespace PizzeriaDatabaseImplement.Migrations
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProductId = table.Column<int>(type: "int", nullable: false),
PizzaId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
PizzaId = table.Column<int>(type: "int", nullable: false)
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{

View File

@ -112,9 +112,6 @@ namespace PizzeriaDatabaseImplement.Migrations
b.Property<int>("PizzaId")
.HasColumnType("int");
b.Property<int>("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 =>

View File

@ -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
});

View File

@ -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();
}
}

View File

@ -20,4 +20,8 @@
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>