From 8a4b8a5f7953d459f65af273d6af0e76901a03fb Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Wed, 17 May 2023 17:58:35 +0400 Subject: [PATCH 1/3] Base fixes --- .../BusinessLogic/RequestComponentLogic.cs | 38 ++ .../IRequestComponentLogic.cs | 15 + .../IRequestComponentStorage.cs | 16 + .../ViewModels/RequestComponentViewModel.cs | 29 + .../Implements/RequestComponentStorage.cs | 50 ++ .../20230516114631_fieldFixes.Designer.cs | 499 ++++++++++++++++++ .../Migrations/20230516114631_fieldFixes.cs | 59 +++ 7 files changed, 706 insertions(+) create mode 100644 ComputerStoreBusinessLogic/BusinessLogic/RequestComponentLogic.cs create mode 100644 ComputerStoreContracts/BusinessLogicContracts/IRequestComponentLogic.cs create mode 100644 ComputerStoreContracts/StorageContracts/IRequestComponentStorage.cs create mode 100644 ComputerStoreContracts/ViewModels/RequestComponentViewModel.cs create mode 100644 ComputerStoreDatabaseImplement/Implements/RequestComponentStorage.cs create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.Designer.cs create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.cs diff --git a/ComputerStoreBusinessLogic/BusinessLogic/RequestComponentLogic.cs b/ComputerStoreBusinessLogic/BusinessLogic/RequestComponentLogic.cs new file mode 100644 index 0000000..a8baa5a --- /dev/null +++ b/ComputerStoreBusinessLogic/BusinessLogic/RequestComponentLogic.cs @@ -0,0 +1,38 @@ +using ComputerStoreContracts.BusinessLogicContracts; +using ComputerStoreContracts.SearchModels; +using ComputerStoreContracts.StorageContracts; +using ComputerStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreBusinessLogic.BusinessLogic +{ + public class RequestComponentLogic : IRequestComponentLogic + { + private readonly ILogger _logger; + private readonly IRequestComponentStorage _requestComponentStorage; + public RequestComponentLogic(ILogger logger, IRequestComponentStorage requestComponentStorage) + { + _logger = logger; + _requestComponentStorage = requestComponentStorage; + } + + public List? ReadList(RequestSearchModel model) + { + _logger.LogInformation("ReadList. PCID:{ PCID}. OrderID:{ OrderID}. ID:{ ID}", model?.PCID, model?.OrderID,model?.ID); + var list = model.ID == null ? _requestComponentStorage.GetFullList() : _requestComponentStorage.GetFilteredList(model); + + if(list == null) + { + _logger.LogWarning("ReadList return null list"); + return new(); + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + } +} diff --git a/ComputerStoreContracts/BusinessLogicContracts/IRequestComponentLogic.cs b/ComputerStoreContracts/BusinessLogicContracts/IRequestComponentLogic.cs new file mode 100644 index 0000000..e5d4166 --- /dev/null +++ b/ComputerStoreContracts/BusinessLogicContracts/IRequestComponentLogic.cs @@ -0,0 +1,15 @@ +using ComputerStoreContracts.SearchModels; +using ComputerStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreContracts.BusinessLogicContracts +{ + public interface IRequestComponentLogic + { + List? ReadList(RequestSearchModel? model); + } +} diff --git a/ComputerStoreContracts/StorageContracts/IRequestComponentStorage.cs b/ComputerStoreContracts/StorageContracts/IRequestComponentStorage.cs new file mode 100644 index 0000000..98f1b19 --- /dev/null +++ b/ComputerStoreContracts/StorageContracts/IRequestComponentStorage.cs @@ -0,0 +1,16 @@ +using ComputerStoreContracts.SearchModels; +using ComputerStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreContracts.StorageContracts +{ + public interface IRequestComponentStorage + { + List GetFullList(); + List GetFilteredList(RequestSearchModel model); + } +} diff --git a/ComputerStoreContracts/ViewModels/RequestComponentViewModel.cs b/ComputerStoreContracts/ViewModels/RequestComponentViewModel.cs new file mode 100644 index 0000000..73a6a4d --- /dev/null +++ b/ComputerStoreContracts/ViewModels/RequestComponentViewModel.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreContracts.ViewModels +{ + public class RequestComponentViewModel + { + [DisplayName("RequestID")] + public int RequestID { get; set; } + + [DisplayName("ComponentID")] + public int ComponentID { get; set; } + + [DisplayName("Component's name")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Component's count")] + public int ComponentCount { get; set; } + + [DisplayName("PCID")] + public int PCID { get; set; } + + } +} diff --git a/ComputerStoreDatabaseImplement/Implements/RequestComponentStorage.cs b/ComputerStoreDatabaseImplement/Implements/RequestComponentStorage.cs new file mode 100644 index 0000000..c34490b --- /dev/null +++ b/ComputerStoreDatabaseImplement/Implements/RequestComponentStorage.cs @@ -0,0 +1,50 @@ +using ComputerStoreContracts.SearchModels; +using ComputerStoreContracts.StorageContracts; +using ComputerStoreContracts.ViewModels; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreDatabaseImplement.Implements +{ + public class RequestComponentStorage : IRequestComponentStorage + { + public List GetFilteredList(RequestSearchModel model) + { + using var context = new ComputerStoreDatabase(); + var list = new List(); + foreach (var pc in context.RequestComponents.Include(x => x.Component).Include(x => x.Request).Where(x => x.PCID == null && x.RequestID == model.ID)) + { + list.Add(new RequestComponentViewModel + { + RequestID = pc.RequestID, + ComponentID = pc.ComponentID, + ComponentName = pc.Component.Name, + ComponentCount = pc.Count, + }); + } + return list; + } + + public List GetFullList() + { + using var context = new ComputerStoreDatabase(); + + var list = new List(); + + foreach(var pc in context.RequestComponents.Include(x => x.Component).Include(x => x.Request).Where(x => x.PCID == null)) + { + list.Add(new RequestComponentViewModel { + RequestID = pc.RequestID, + ComponentID = pc.ComponentID, + ComponentName = pc.Component.Name, + ComponentCount = pc.Count, + }); + } + return list; + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.Designer.cs b/ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.Designer.cs new file mode 100644 index 0000000..61fecbf --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.Designer.cs @@ -0,0 +1,499 @@ +// +using System; +using ComputerStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerStoreDatabase))] + [Migration("20230516114631_fieldFixes")] + partial class fieldFixes + { + /// + 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("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.HasIndex("ProductID"); + + b.ToTable("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ConsignmentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ConsignmentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ConsignmentProducts"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SellerID") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("PCs"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("PCID"); + + b.HasIndex("RequestID"); + + b.ToTable("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Sellers"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_consignments") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null) + .WithMany("Consignments") + .HasForeignKey("ProductID"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment") + .WithMany("Products") + .HasForeignKey("ConsignmentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consignment"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") + .WithMany("Orders") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Seller"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("PCs") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("Products") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("ConsignmentComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_requests") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("RequestComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") + .WithMany("Components") + .HasForeignKey("PCID"); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") + .WithMany("PCs") + .HasForeignKey("RequestID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("PC"); + + b.Navigation("Request"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("ConsignmentComponents"); + + b.Navigation("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Navigation("PCs"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Navigation("_consignments"); + + b.Navigation("_requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + + b.Navigation("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Navigation("PCs"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.cs b/ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.cs new file mode 100644 index 0000000..43df533 --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230516114631_fieldFixes.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + /// + public partial class fieldFixes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents"); + + migrationBuilder.AlterColumn( + name: "PCID", + table: "RequestComponents", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCs", + principalColumn: "ID"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents"); + + migrationBuilder.AlterColumn( + name: "PCID", + table: "RequestComponents", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCs", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + } + } +} From f64c7b284c5cf399c363b6007de19c95939c4f4d Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Wed, 17 May 2023 18:34:28 +0400 Subject: [PATCH 2/3] Relation and models fixes. --- .../ComputerStoreDatabase.cs | 2 +- .../20230517142400_RelationFixes.Designer.cs | 496 ++++++++++++++++++ .../20230517142400_RelationFixes.cs | 112 ++++ .../ComputerStoreDatabaseModelSnapshot.cs | 13 +- ComputerStoreDatabaseImplement/Models/PC.cs | 12 +- .../Models/Product.cs | 17 +- .../Models/RequestComponent.cs | 6 +- .../Models/Seller.cs | 2 +- 8 files changed, 635 insertions(+), 25 deletions(-) create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.Designer.cs create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.cs diff --git a/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs b/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs index fd3d783..8d120be 100644 --- a/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs +++ b/ComputerStoreDatabaseImplement/ComputerStoreDatabase.cs @@ -14,7 +14,7 @@ namespace ComputerStoreDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Initial Catalog=ComputerStoreDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=YUEEJKE\SQLEXPRESS;Initial Catalog=ComputerStoreDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.Designer.cs b/ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.Designer.cs new file mode 100644 index 0000000..f579d22 --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.Designer.cs @@ -0,0 +1,496 @@ +// +using System; +using ComputerStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerStoreDatabase))] + [Migration("20230517142400_RelationFixes")] + partial class RelationFixes + { + /// + 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("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.HasIndex("ProductID"); + + b.ToTable("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ConsignmentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ConsignmentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ConsignmentProducts"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SellerID") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("SellerID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("PCs"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("PCID"); + + b.HasIndex("RequestID"); + + b.ToTable("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Sellers"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_consignments") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null) + .WithMany("Consignments") + .HasForeignKey("ProductID"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment") + .WithMany("Products") + .HasForeignKey("ConsignmentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consignment"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") + .WithMany("Orders") + .HasForeignKey("SellerID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Seller"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("PCs") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("Products") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("ConsignmentComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_requests") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("RequestComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") + .WithMany("Components") + .HasForeignKey("PCID"); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") + .WithMany("PCs") + .HasForeignKey("RequestID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("PC"); + + b.Navigation("Request"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("ConsignmentComponents"); + + b.Navigation("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Navigation("PCs"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Navigation("_consignments"); + + b.Navigation("_requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + + b.Navigation("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Navigation("PCs"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.cs b/ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.cs new file mode 100644 index 0000000..aa17968 --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230517142400_RelationFixes.cs @@ -0,0 +1,112 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + /// + public partial class RelationFixes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Sellers_OrderID", + table: "Orders"); + + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents"); + + migrationBuilder.DropIndex( + name: "IX_Orders_OrderID", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "OrderID", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "PCID", + table: "RequestComponents", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_SellerID", + table: "Orders", + column: "SellerID"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Sellers_SellerID", + table: "Orders", + column: "SellerID", + principalTable: "Sellers", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCs", + principalColumn: "ID"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Sellers_SellerID", + table: "Orders"); + + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents"); + + migrationBuilder.DropIndex( + name: "IX_Orders_SellerID", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "PCID", + table: "RequestComponents", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "OrderID", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateIndex( + name: "IX_Orders_OrderID", + table: "Orders", + column: "OrderID"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Sellers_OrderID", + table: "Orders", + column: "OrderID", + principalTable: "Sellers", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCs_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCs", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs b/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs index 09a4479..f6b3b2d 100644 --- a/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs +++ b/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs @@ -138,9 +138,6 @@ namespace ComputerStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); - b.Property("OrderID") - .HasColumnType("int"); - b.Property("Price") .HasColumnType("float"); @@ -152,7 +149,7 @@ namespace ComputerStoreDatabaseImplement.Migrations b.HasKey("ID"); - b.HasIndex("OrderID"); + b.HasIndex("SellerID"); b.ToTable("Orders"); }); @@ -274,7 +271,7 @@ namespace ComputerStoreDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); - b.Property("PCID") + b.Property("PCID") .HasColumnType("int"); b.Property("RequestID") @@ -359,7 +356,7 @@ namespace ComputerStoreDatabaseImplement.Migrations { b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") .WithMany("Orders") - .HasForeignKey("OrderID") + .HasForeignKey("SellerID") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -428,9 +425,7 @@ namespace ComputerStoreDatabaseImplement.Migrations b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") .WithMany("Components") - .HasForeignKey("PCID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("PCID"); b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") .WithMany("PCs") diff --git a/ComputerStoreDatabaseImplement/Models/PC.cs b/ComputerStoreDatabaseImplement/Models/PC.cs index 56d6eea..704c246 100644 --- a/ComputerStoreDatabaseImplement/Models/PC.cs +++ b/ComputerStoreDatabaseImplement/Models/PC.cs @@ -87,12 +87,16 @@ namespace ComputerStoreDatabaseImplement.Models var pcComponents = context.RequestComponents.Where(rec => rec.PCID == model.ID && rec.RequestID == model.RequestID).ToList(); if(pcComponents != null && pcComponents.Count > 0) { - context.RequestComponents.RemoveRange(pcComponents.Where(rec => !model.PCComponents.ContainsKey(rec.ComponentID) && rec.RequestID == model.RequestID)); - context.SaveChanges(); + if(pcComponents.Where(rec => !model.PCComponents.ContainsKey(rec.ComponentID) && rec.RequestID == model.RequestID).Any()) + { + context.RequestComponents.RemoveRange(pcComponents.Where(rec => !model.PCComponents.ContainsKey(rec.ComponentID) && rec.RequestID == model.RequestID)); + context.SaveChanges(); + } + foreach(var updateComponent in pcComponents) { - updateComponent.Count = model.PCComponents[updateComponent.PCID].Item2; - model.PCComponents.Remove(updateComponent.PCID); + updateComponent.Count = model.PCComponents[updateComponent.ComponentID].Item2; + model.PCComponents.Remove(updateComponent.ComponentID); } context.SaveChanges(); } diff --git a/ComputerStoreDatabaseImplement/Models/Product.cs b/ComputerStoreDatabaseImplement/Models/Product.cs index a59a758..9369614 100644 --- a/ComputerStoreDatabaseImplement/Models/Product.cs +++ b/ComputerStoreDatabaseImplement/Models/Product.cs @@ -83,20 +83,23 @@ namespace ComputerStoreDatabaseImplement.Models public void UpdateComponents(ComputerStoreDatabase context, ProductBindingModel model) { var productComponents = context.ProductComponents.Where(rec => rec.ProductID == model.ID).ToList(); - if(productComponents != null && productComponents.Count > 0) + if (productComponents != null && productComponents.Count > 0) { - context.ProductComponents.RemoveRange(productComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentID))); - context.SaveChanges(); - foreach(var updateComponent in productComponents) + if (productComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentID)).Any()) { - updateComponent.Count = model.ProductComponents[updateComponent.ID].Item2; - model.ProductComponents.Remove(updateComponent.ID); + context.ProductComponents.RemoveRange(productComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentID))); + context.SaveChanges(); + } + foreach (var updateComponent in productComponents.Where(x => model.ProductComponents.ContainsKey(x.ComponentID))) + { + updateComponent.Count = model.ProductComponents[updateComponent.ComponentID].Item2; + model.ProductComponents.Remove(updateComponent.ComponentID); } context.SaveChanges(); } var product = context.Products.First(x => x.ID == ID); - foreach(var pc in model.ProductComponents) + foreach (var pc in model.ProductComponents) { context.ProductComponents.Add(new ProductComponent { diff --git a/ComputerStoreDatabaseImplement/Models/RequestComponent.cs b/ComputerStoreDatabaseImplement/Models/RequestComponent.cs index 3157632..3e54ed0 100644 --- a/ComputerStoreDatabaseImplement/Models/RequestComponent.cs +++ b/ComputerStoreDatabaseImplement/Models/RequestComponent.cs @@ -17,13 +17,13 @@ namespace ComputerStoreDatabaseImplement.Models [Required] public int ComponentID { get; set; } - [Required] - public int PCID { get; set; } + + public int? PCID { get; set; } [Required] public int Count { get; set; } - public virtual PC PC { get; set; } = new(); + public virtual PC? PC { get; set; } = new(); public virtual Component Component { get; set; } = new(); public virtual Request Request { get; set; } = new(); } diff --git a/ComputerStoreDatabaseImplement/Models/Seller.cs b/ComputerStoreDatabaseImplement/Models/Seller.cs index a48e66a..fda93c5 100644 --- a/ComputerStoreDatabaseImplement/Models/Seller.cs +++ b/ComputerStoreDatabaseImplement/Models/Seller.cs @@ -23,7 +23,7 @@ namespace ComputerStoreDatabaseImplement.Models public string? LastName { get; private set; } = string.Empty; public string? MiddleName { get; private set; } = string.Empty; - [ForeignKey("OrderID")] + [ForeignKey("SellerID")] public virtual List Orders { get; set; } = new(); public static Seller? Create(SellerBindingModel? model) From f7c05cc17d46384014ffce05daa51be5f85a3a22 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Wed, 17 May 2023 18:36:32 +0400 Subject: [PATCH 3/3] Model fixes. --- ComputerStoreDatabaseImplement/Models/PC.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ComputerStoreDatabaseImplement/Models/PC.cs b/ComputerStoreDatabaseImplement/Models/PC.cs index 704c246..3714977 100644 --- a/ComputerStoreDatabaseImplement/Models/PC.cs +++ b/ComputerStoreDatabaseImplement/Models/PC.cs @@ -93,7 +93,7 @@ namespace ComputerStoreDatabaseImplement.Models context.SaveChanges(); } - foreach(var updateComponent in pcComponents) + foreach(var updateComponent in pcComponents.Where(x => model.PCComponents.ContainsKey(x.ComponentID) && x.RequestID == model.RequestID)) { updateComponent.Count = model.PCComponents[updateComponent.ComponentID].Item2; model.PCComponents.Remove(updateComponent.ComponentID);