diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/BuildSearchModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/BuildSearchModel.cs index 5b6b533..1af793c 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/BuildSearchModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/BuildSearchModel.cs @@ -4,6 +4,7 @@ { public int? Id { get; set; } public int VendorId { get; set; } + public int? ProductId { get; set; } public string? Name { get; set; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs index 0be2db5..c2d1673 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs @@ -39,6 +39,5 @@ namespace ComputerHardwareStoreDatabaseImplement public virtual DbSet Purchases { set; get; } public virtual DbSet PurchaseBuilds { set; get; } public virtual DbSet PurchaseProducts { set; get; } - public virtual DbSet Vendors { set; get; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/BuildStorage.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/BuildStorage.cs index d546f43..f192b82 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/BuildStorage.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/BuildStorage.cs @@ -29,10 +29,18 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements } using var context = new ComputerHardwareStoreDBContext(); return context.Builds + // только те, что созданы пользователем .Include(b => b.Vendor) - .Where(b => b.Vendor.Id == model.VendorId ) - .Where(b => b.Name.Contains(model.Name)) + .Where(b => b.Vendor.Id == model.VendorId + // если есть хотя бы 1 общий компонент с товарами + && !model.ProductId.HasValue || b.Components.FirstOrDefault( + c => c.Component.ProductComponents.FirstOrDefault( + p => p.ProductId == model.ProductId) + != null) + != null) + // вместе с комментами .Include(b => b.Comments) + // вместе с компонентами .Include(b => b.Components) .ThenInclude(b => b.Component) .Select(b => b.GetViewModel) diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/Vendor.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/VendorStorage.cs similarity index 100% rename from ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/Vendor.cs rename to ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Implements/VendorStorage.cs