From 92235ba186a0c2660c8536586c683b4b365c3f77 Mon Sep 17 00:00:00 2001 From: the Date: Wed, 24 May 2023 18:51:13 +0400 Subject: [PATCH] word --- .../BusinessLogics/ReportLogic.cs | 11 +- .../BindingModels/SupplyBindingModel.cs | 10 +- .../ViewModels/SupplyViewModel.cs | 5 + .../ComputerShopDatabase.cs | 2 +- .../Implements/SupplyStorage.cs | 8 +- .../20230524135850_ordermig.Designer.cs | 538 ++++++++++++++++++ .../Migrations/20230524135850_ordermig.cs | 29 + .../ComputerShopDatabaseModelSnapshot.cs | 6 +- .../Models/Supply.cs | 26 +- 9 files changed, 618 insertions(+), 17 deletions(-) create mode 100644 ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.Designer.cs create mode 100644 ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.cs diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs index 515fd18..eb15b9c 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ComputerShopDataModels.Enums; namespace ComputerShopBusinessLogic.BusinessLogics { @@ -37,7 +38,10 @@ namespace ComputerShopBusinessLogic.BusinessLogics public List GetComponentReceivings(List ids) { var result = new List(); - + + var supplies1 = _supplyStorage.GetFullList(); + var recs = _receivingStorage.GetFullList(); + foreach (int id in ids) { var component = _componentStorage.GetElement(new ComponentSearchModel() @@ -51,13 +55,12 @@ namespace ComputerShopBusinessLogic.BusinessLogics var receivings = new List(); - foreach(var supply in supplies) { if (supply.ReceivingId.HasValue) { var receiving = _receivingStorage.GetElement(new() { Id = supply.ReceivingId.Value }); - if (receiving != null && receivings.Contains(receiving)) + if (receiving != null && !receivings.Contains(receiving)) { receivings.Add(receiving); } @@ -68,7 +71,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics var receivingnames = new List(); foreach (var receiving in receivings) { - receivingnames.Add($"Id: {receiving.Id}. Date: {receiving.Status}."); + receivingnames.Add($"Id: {receiving.Id}. Status: {Enum.GetName(typeof(EquipmentReceivingStatus), receiving.Status)}."); } if(receivingnames.Count > 0 && component != null) { diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs index f1f85d1..2df7b64 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs @@ -18,12 +18,18 @@ namespace ComputerShopContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } - + public DateTime? DateImplement { get; set; } + public Dictionary SupplyOrders { get; set; } = new(); + + public Dictionary SupplyComponents + { + get; + set; + } = new(); } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs index b2e89a7..0656c0f 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs @@ -32,6 +32,11 @@ namespace ComputerShopContracts.ViewModels get; set; } = new(); + public Dictionary SupplyComponents + { + get; + set; + } = new(); } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs index 69a127f..856646a 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs @@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabaseCW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabaseCWW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs index 8bc56a9..e523a9c 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs @@ -52,7 +52,7 @@ namespace ComputerShopDatabaseImplement.Implements return new(); } using var context = new ComputerShopDatabase(); - if(model.ComponentId.HasValue) + if(!model.ComponentId.HasValue) return context.Supplies .Include(x => x.Orders) .ThenInclude(x => x.Order) @@ -66,9 +66,9 @@ namespace ComputerShopDatabaseImplement.Implements .Include(x => x.Orders) .ThenInclude(x => x.Order) .Include(x => x.Receiving) - .Include(x => x.ComponentSupplies) + .Include(x => x.Components) .ThenInclude(x => x.Component) - .Where(x => x.ComponentSupplies.Any(x => x.ComponentId == model.ComponentId)) + .Where(x => x.Components.Any(x => x.ComponentId == model.ComponentId)) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -80,6 +80,8 @@ namespace ComputerShopDatabaseImplement.Implements return context.Supplies .Include(x => x.Orders) .ThenInclude(x => x.Order) + .Include(x => x.Components) + .ThenInclude(x => x.Component) .Include(x => x.Receiving) .ToList() .Select(x => x.GetViewModel) diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.Designer.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.Designer.cs new file mode 100644 index 0000000..1f73480 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.Designer.cs @@ -0,0 +1,538 @@ +// +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("20230524135850_ordermig")] + partial class ordermig + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Assemblies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("ComponentId"); + + b.ToTable("AssemblyComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("OrderId"); + + b.ToTable("AssemblyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("SupplyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("SupplyId"); + + b.ToTable("ComponentSupplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("EquipmentReceivings"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ComponentId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReceivingId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ReceivingId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("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") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", "Receiving") + .WithMany("Supplies") + .HasForeignKey("ReceivingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Receiving"); + }); + + 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 + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.cs new file mode 100644 index 0000000..5f5b121 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230524135850_ordermig.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + /// + public partial class ordermig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "OrderId", + table: "Supplies"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "OrderId", + table: "Supplies", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs index 71fe12d..2ad85ee 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs @@ -288,10 +288,8 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); - b.Property("OrderId") - .HasColumnType("int"); - - b.Property("ReceivingId") + b.Property("ReceivingId") + .IsRequired() .HasColumnType("int"); b.Property("Status") diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs index 85c9cb5..61920d2 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs @@ -22,8 +22,6 @@ namespace ComputerShopDatabaseImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } - - public int OrderId { get; set; } public int ClientId { get; set; } public int? ReceivingId { get; set; } @@ -31,6 +29,7 @@ namespace ComputerShopDatabaseImplement.Models private Dictionary? _supplyOrders = null; + private Dictionary? _supplyComponents = null; [NotMapped] public Dictionary SupplyOrders { @@ -44,10 +43,23 @@ namespace ComputerShopDatabaseImplement.Models return _supplyOrders; } } + [NotMapped] + public Dictionary SupplyComponents + { + get + { + if (_supplyComponents == null) + { + _supplyComponents = Components + .ToDictionary(recPC => recPC.SupplyId, recPC => recPC.Component as IComponentModel); + } + return _supplyComponents; + } + } [ForeignKey("SupplyId")] public virtual List Orders { get; set; } = new(); [ForeignKey("SupplyId")] - public virtual List ComponentSupplies { get; set; } = new(); + public virtual List Components { get; set; } = new(); public static Supply Create(ComputerShopDatabase context, SupplyBindingModel model) { @@ -58,10 +70,16 @@ namespace ComputerShopDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ReceivingId = model.ReceivingId, Orders = model.SupplyOrders.Select(x => new SupplyOrder { Order = context.Orders.First(y => y.Id == x.Key), + }).ToList(), + Components = model.SupplyComponents.Select(x => new + ComponentSupply + { + Component = context.Components.First(y => y.Id == x.Key), }).ToList() }; } @@ -81,6 +99,8 @@ namespace ComputerShopDatabaseImplement.Models DateCreate = DateCreate, DateImplement = DateImplement, SupplyOrders = SupplyOrders, + SupplyComponents = SupplyComponents, + ReceivingId = ReceivingId, ClientId = ClientId }; public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model)