From a30de13f4e1dc18d42df768744a12141fe407667 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Tue, 30 Apr 2024 19:49:13 +0400 Subject: [PATCH] product mtm --- .../Models/Product.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs index a7af49c..023758a 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs @@ -39,12 +39,15 @@ namespace ComputerHardwareStoreDatabaseImplement.Models Id = model.Id, Name = model.Name, Price = model.Price, - Components = model.ProductComponents.Select(x => - new ProductComponent - { - Component = context.Components.First(y => y.Id == x.Key), - Count = x.Value.Item2 - }).ToList() + Components = context.Components + .Where(c => model.ProductComponents.ContainsKey(c.Id)) + .Select(c => new ProductComponent() + { + ProductId = model.Id, + ComponentId = c.Id, + Component = c, + Count = model.ProductComponents[c.Id].Item2 + }).ToList(), }; } public void Update(ProductBindingModel model)