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