fix
This commit is contained in:
parent
adaa621ff6
commit
ae632c5cb4
@ -45,6 +45,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
if (order == null) {
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
order.DeleteProducts(context, model);
|
||||
transcation.Commit();
|
||||
return order.GetViewModel;
|
||||
|
284
ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724093852_Migration06.Designer.cs
generated
Normal file
284
ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724093852_Migration06.Designer.cs
generated
Normal file
@ -0,0 +1,284 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ElectronicsShopDataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20240724093852_Migration06")]
|
||||
partial class Migration06
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("CostNum")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("EmployeeID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("EmployeeID");
|
||||
|
||||
b.ToTable("CostItems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("EmployeeFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("OrderID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ProductID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderID");
|
||||
|
||||
b.HasIndex("ProductID");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DatePaymeant")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("OrderID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PayOption")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("SumPayment")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("OrderID");
|
||||
|
||||
b.ToTable("Paymeants");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("CostItemID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("CostItemID");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany()
|
||||
.HasForeignKey("EmployeeID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null)
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", "_order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Product", "_product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("_order");
|
||||
|
||||
b.Navigation("_product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", null)
|
||||
.WithMany("Payments")
|
||||
.HasForeignKey("OrderID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem")
|
||||
.WithMany()
|
||||
.HasForeignKey("CostItemID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CostItem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Payments");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Migration06 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Paymeants_Orders_PaymentID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Paymeants_PaymentID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PaymentID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Paymeants_OrderID",
|
||||
table: "Paymeants",
|
||||
column: "OrderID");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Paymeants_Orders_OrderID",
|
||||
table: "Paymeants",
|
||||
column: "OrderID",
|
||||
principalTable: "Orders",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Paymeants_Orders_OrderID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Paymeants_OrderID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PaymentID",
|
||||
table: "Paymeants",
|
||||
type: "int",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Paymeants_PaymentID",
|
||||
table: "Paymeants",
|
||||
column: "PaymentID");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Paymeants_Orders_PaymentID",
|
||||
table: "Paymeants",
|
||||
column: "PaymentID",
|
||||
principalTable: "Orders",
|
||||
principalColumn: "ID");
|
||||
}
|
||||
}
|
||||
}
|
285
ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724094839_Migration07.Designer.cs
generated
Normal file
285
ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724094839_Migration07.Designer.cs
generated
Normal file
@ -0,0 +1,285 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using ElectronicsShopDataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20240724094839_Migration07")]
|
||||
partial class Migration07
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("CostNum")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("EmployeeID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("EmployeeID");
|
||||
|
||||
b.ToTable("CostItems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("EmployeeFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Login")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("OrderID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ProductID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderID");
|
||||
|
||||
b.HasIndex("ProductID");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DatePaymeant")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("OrderID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PayOption")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("PaymentID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("SumPayment")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("PaymentID");
|
||||
|
||||
b.ToTable("Paymeants");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("CostItemID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("CostItemID");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany()
|
||||
.HasForeignKey("EmployeeID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null)
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", "_order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Product", "_product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("_order");
|
||||
|
||||
b.Navigation("_product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", null)
|
||||
.WithMany("Payments")
|
||||
.HasForeignKey("PaymentID");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem")
|
||||
.WithMany()
|
||||
.HasForeignKey("CostItemID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CostItem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Payments");
|
||||
|
||||
b.Navigation("Products");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Migration07 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Paymeants_Orders_OrderID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Paymeants_OrderID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PaymentID",
|
||||
table: "Paymeants",
|
||||
type: "int",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Paymeants_PaymentID",
|
||||
table: "Paymeants",
|
||||
column: "PaymentID");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Paymeants_Orders_PaymentID",
|
||||
table: "Paymeants",
|
||||
column: "PaymentID",
|
||||
principalTable: "Orders",
|
||||
principalColumn: "ID");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Paymeants_Orders_PaymentID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Paymeants_PaymentID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PaymentID",
|
||||
table: "Paymeants");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Paymeants_OrderID",
|
||||
table: "Paymeants",
|
||||
column: "OrderID");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Paymeants_Orders_OrderID",
|
||||
table: "Paymeants",
|
||||
column: "OrderID",
|
||||
principalTable: "Orders",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
@ -75,11 +75,20 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
ProductList = ProductList,
|
||||
};
|
||||
|
||||
public void Update(OrderBindingModel model) {
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
Sum = model.Sum;
|
||||
}
|
||||
|
||||
public void UpdateProducts(Database context,OrderBindingModel model) {
|
||||
var orderProducts = context.OrderProducts.Where(rec => rec.OrderID == model.ID).ToList();
|
||||
if (orderProducts != null && orderProducts.Count > 0) {
|
||||
// нужно удалить те, которые отсутствуют в модели
|
||||
context.OrderProducts.RemoveRange(orderProducts.Where(rec => !model.ProductList.ContainsKey(rec.ProductID)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateProducts in orderProducts) {
|
||||
updateProducts.Count = model.ProductList[updateProducts.ProductID].Item2;
|
||||
model.ProductList.Remove(updateProducts.ProductID);
|
||||
@ -110,9 +119,5 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
context.OrderProducts.RemoveRange(orderProducts.Where(rec => !model.ProductList.ContainsKey(rec.ProductID)));
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public void SumUpdate(double sumDeduct) {
|
||||
Sum -= sumDeduct;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user