From c229b58d9ddb35d0375ab156c4ec5b6114cc9806 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Wed, 1 May 2024 17:42:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D1=81=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=BA=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BA=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchModels/ProductSearchModel.cs | 4 ++-- .../Models/IProductModel.cs | 1 + .../Implements/ProductStorage.cs | 8 +++++++- .../Models/Component.cs | 2 ++ .../Models/Product.cs | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/ProductSearchModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/ProductSearchModel.cs index 1271144..80dacff 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/ProductSearchModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/ProductSearchModel.cs @@ -4,7 +4,7 @@ { public int? Id { get; set; } public string? Name { get; set; } - public int VendorId { get; set; } - public List? Builds { get; set; } + public int StoreKeeperId { get; set; } + public int? BuildId { get; set; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs b/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs index a38ae89..a0dbef4 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs @@ -4,6 +4,7 @@ { string Name { get; } double Price { get; } + int StoreKeeperId { get; } public Dictionary ProductComponents { get; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/ProductStorage.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/ProductStorage.cs index ae83b6b..d27a131 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/ProductStorage.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/ProductStorage.cs @@ -27,7 +27,13 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements } using var context = new ComputerHardwareStoreDBContext(); return context.Products - .Where(p => p.Name.Contains(model.Name)) + .Where(p => (p.StoreKeeperId == model.StoreKeeperId) + // есть хотя бы 1 общий со сборкой компонент + && (!model.BuildId.HasValue || p.Components.FirstOrDefault + (c => c.Component.BuldComponents.FirstOrDefault( + b => b.BuildId == model.BuildId) + != null) + != null)) .Include(p => p.Components) .ThenInclude(p => p.Component) .Select(p => p.GetViewModel) diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs index 4acbece..80f2389 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs @@ -20,6 +20,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Models [ForeignKey("ComponentId")] public virtual List ProductComponents { get; set; } = new(); + [ForeignKey("ComponentId")] + public virtual List BuldComponents { get; set; } = new(); public static Component? Create(ComponentBindingModel model) { if (model == null) diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs index 023758a..f86ed01 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs @@ -14,6 +14,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models public string Name { get; set; } = string.Empty; [Required] public double Price { get; set; } + public int StoreKeeperId { get; private set; } private Dictionary? _productComponents = null; [NotMapped] public Dictionary ProductComponents