Supply fix

This commit is contained in:
2023-05-18 23:48:28 +04:00
20 changed files with 1078 additions and 57 deletions

View File

@@ -0,0 +1,530 @@
// <auto-generated />
using System;
using ComputerShopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ComputerShopDatabaseImplement.Migrations
{
[DbContext(typeof(ComputerShopDatabase))]
[Migration("20230518181418_supplymig")]
partial class supplymig
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AssemblyName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Assemblies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AssemblyId")
.HasColumnType("int");
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AssemblyId");
b.HasIndex("ComponentId");
b.ToTable("AssemblyComponents");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AssemblyId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("OrderId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AssemblyId");
b.HasIndex("OrderId");
b.ToTable("AssemblyOrders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.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("ComputerShopDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Components");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("SupplyId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("SupplyId");
b.ToTable("ComponentSupplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId")
.HasColumnType("int");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("EquipmentReceivings");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.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<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Orders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ComponentId");
b.ToTable("Purchases");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", 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<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("OrderId")
.HasColumnType("int");
b.Property<int?>("ReceivingId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ReceivingId");
b.ToTable("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", 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>("SupplyId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("SupplyId");
b.ToTable("SupplyOrders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Assemblies")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly")
.WithMany("Components")
.HasForeignKey("AssemblyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
.WithMany("AssemblyComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Assembly");
b.Navigation("Component");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly")
.WithMany("Orders")
.HasForeignKey("AssemblyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order")
.WithMany("Assemblies")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Assembly");
b.Navigation("Order");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Components")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
.WithMany("Supplies")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply")
.WithMany("ComponentSupplies")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Supply");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("EquipmentReceivings")
.HasForeignKey("ClientId");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Orders")
.HasForeignKey("ClientId");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Purchases")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
.WithMany("Purchases")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Component");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Supplies")
.HasForeignKey("ClientId");
b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null)
.WithMany("Supplies")
.HasForeignKey("ReceivingId");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order")
.WithMany("SupplyOrders")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply")
.WithMany("Orders")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Supply");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Assemblies");
b.Navigation("Components");
b.Navigation("EquipmentReceivings");
b.Navigation("Orders");
b.Navigation("Purchases");
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("AssemblyComponents");
b.Navigation("Purchases");
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{
b.Navigation("Assemblies");
b.Navigation("SupplyOrders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b =>
{
b.Navigation("ComponentSupplies");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,95 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ComputerShopDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class supplymig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EquipmentReceivings_Supplies_SupplyId",
table: "EquipmentReceivings");
migrationBuilder.DropIndex(
name: "IX_EquipmentReceivings_SupplyId",
table: "EquipmentReceivings");
migrationBuilder.DropColumn(
name: "SupplyId",
table: "EquipmentReceivings");
migrationBuilder.AlterColumn<int>(
name: "ReceivingId",
table: "Supplies",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.CreateIndex(
name: "IX_Supplies_ReceivingId",
table: "Supplies",
column: "ReceivingId");
migrationBuilder.AddForeignKey(
name: "FK_Supplies_EquipmentReceivings_ReceivingId",
table: "Supplies",
column: "ReceivingId",
principalTable: "EquipmentReceivings",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Supplies_EquipmentReceivings_ReceivingId",
table: "Supplies");
migrationBuilder.DropIndex(
name: "IX_Supplies_ReceivingId",
table: "Supplies");
migrationBuilder.AlterColumn<int>(
name: "ReceivingId",
table: "Supplies",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddColumn<int>(
name: "SupplyId",
table: "EquipmentReceivings",
type: "int",
nullable: true);
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Assemblies",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.CreateIndex(
name: "IX_EquipmentReceivings_SupplyId",
table: "EquipmentReceivings",
column: "SupplyId");
migrationBuilder.AddForeignKey(
name: "FK_EquipmentReceivings_Supplies_SupplyId",
table: "EquipmentReceivings",
column: "SupplyId",
principalTable: "Supplies",
principalColumn: "Id");
}
}
}

View File

@@ -34,7 +34,7 @@ namespace ComputerShopDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("ClientId")
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<double>("Price")
@@ -192,15 +192,10 @@ namespace ComputerShopDatabaseImplement.Migrations
b.Property<int>("Status")
.HasColumnType("int");
b.Property<int?>("SupplyId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("SupplyId");
b.ToTable("EquipmentReceivings");
});
@@ -296,7 +291,7 @@ namespace ComputerShopDatabaseImplement.Migrations
b.Property<int>("OrderId")
.HasColumnType("int");
b.Property<int>("ReceivingId")
b.Property<int?>("ReceivingId")
.HasColumnType("int");
b.Property<int>("Status")
@@ -306,6 +301,8 @@ namespace ComputerShopDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ReceivingId");
b.ToTable("Supplies");
});
@@ -337,9 +334,13 @@ namespace ComputerShopDatabaseImplement.Migrations
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Assemblies")
.HasForeignKey("ClientId");
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
@@ -398,7 +399,7 @@ namespace ComputerShopDatabaseImplement.Migrations
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply")
.WithMany("Supplies")
.WithMany("ComponentSupplies")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -413,10 +414,6 @@ namespace ComputerShopDatabaseImplement.Migrations
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("EquipmentReceivings")
.HasForeignKey("ClientId");
b.HasOne("ComputerShopDatabaseImplement.Models.Supply", null)
.WithMany("Receivings")
.HasForeignKey("SupplyId");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
@@ -450,6 +447,10 @@ namespace ComputerShopDatabaseImplement.Migrations
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Supplies")
.HasForeignKey("ClientId");
b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null)
.WithMany("Supplies")
.HasForeignKey("ReceivingId");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b =>
@@ -502,6 +503,11 @@ namespace ComputerShopDatabaseImplement.Migrations
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{
b.Navigation("Assemblies");
@@ -511,11 +517,9 @@ namespace ComputerShopDatabaseImplement.Migrations
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b =>
{
b.Navigation("ComponentSupplies");
b.Navigation("Orders");
b.Navigation("Receivings");
b.Navigation("Supplies");
});
#pragma warning restore 612, 618
}

View File

@@ -36,6 +36,22 @@ namespace ComputerShopDatabaseImplement.Models
return _assemblyComponents;
}
}
private Dictionary<int, (IOrderModel, int)>? _assemblyOrders = null;
[NotMapped]
public Dictionary<int, (IOrderModel, int)> AssemblyOrders
{
get
{
if (_assemblyOrders == null)
{
_assemblyOrders = Orders
.ToDictionary(recPC => recPC.OrderId, recPC =>
(recPC.Order as IOrderModel, recPC.Count));
}
return _assemblyOrders;
}
}
[ForeignKey("AssemblyId")]
public virtual List<AssemblyComponent> Components { get; set; } = new();
[ForeignKey("AssemblyId")]
@@ -54,6 +70,12 @@ namespace ComputerShopDatabaseImplement.Models
{
Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList(),
Orders = model.AssemblyOrders.Select(x => new
AssemblyOrder
{
Order = context.Orders.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
@@ -68,6 +90,7 @@ namespace ComputerShopDatabaseImplement.Models
AssemblyName = AssemblyName,
Price = Price,
AssemblyComponents = AssemblyComponents,
AssemblyOrders = AssemblyOrders,
ClientId = ClientId
};
public void UpdateComponents(ComputerShopDatabase context, AssemblyBindingModel model)

View File

@@ -5,6 +5,7 @@ using ComputerShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -19,6 +20,9 @@ namespace ComputerShopDatabaseImplement.Models
public int Id { get; set; }
public EquipmentReceivingStatus Status { get; private set; } = EquipmentReceivingStatus.Неизвестен;
[ForeignKey("ReceivingId")]
public List<Supply> Supplies { get; set; } = new();
public static EquipmentReceiving? Create(EquipmentReceivingBindingModel? model)
{
if (model == null)

View File

@@ -26,7 +26,7 @@ namespace ComputerShopDatabaseImplement.Models
public int OrderId { get; set; }
public int ReceivingId { get; set; }
private Dictionary<int, (int, IOrderModel)>? _supplyOrders =
private Dictionary<int, (IOrderModel, int)>? _supplyOrders =
null;
[NotMapped]
public Dictionary<int, (int, IOrderModel)> SupplyOrders
@@ -45,9 +45,7 @@ namespace ComputerShopDatabaseImplement.Models
[ForeignKey("SupplyId")]
public virtual List<SupplyOrder> Orders { get; set; } = new();
[ForeignKey("SupplyId")]
public virtual List<EquipmentReceiving> Receivings { get; set; } = new();
[ForeignKey("SupplyId")]
public virtual List<ComponentSupply> Supplies { get; set; } = new();
public virtual List<ComponentSupply> ComponentSupplies { get; set; } = new();
public static Supply Create(ComputerShopDatabase context, SupplyBindingModel model)
{