поиск продуктов по сборкам
This commit is contained in:
parent
c229b58d9d
commit
d04752b2ba
ComputerHardwareStore
ComputerHardwareStoreContracts/SearchModels
ComputerHardwareStoreDatabaseImplement
@ -4,6 +4,7 @@
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public int VendorId { get; set; }
|
public int VendorId { get; set; }
|
||||||
|
public int? ProductId { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,5 @@ namespace ComputerHardwareStoreDatabaseImplement
|
|||||||
public virtual DbSet<Purchase> Purchases { set; get; }
|
public virtual DbSet<Purchase> Purchases { set; get; }
|
||||||
public virtual DbSet<PurchaseBuild> PurchaseBuilds { set; get; }
|
public virtual DbSet<PurchaseBuild> PurchaseBuilds { set; get; }
|
||||||
public virtual DbSet<PurchaseProduct> PurchaseProducts { set; get; }
|
public virtual DbSet<PurchaseProduct> PurchaseProducts { set; get; }
|
||||||
public virtual DbSet<Vendor> Vendors { set; get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,18 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new ComputerHardwareStoreDBContext();
|
using var context = new ComputerHardwareStoreDBContext();
|
||||||
return context.Builds
|
return context.Builds
|
||||||
|
// только те, что созданы пользователем
|
||||||
.Include(b => b.Vendor)
|
.Include(b => b.Vendor)
|
||||||
.Where(b => b.Vendor.Id == model.VendorId )
|
.Where(b => b.Vendor.Id == model.VendorId
|
||||||
.Where(b => b.Name.Contains(model.Name))
|
// если есть хотя бы 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.Comments)
|
||||||
|
// вместе с компонентами
|
||||||
.Include(b => b.Components)
|
.Include(b => b.Components)
|
||||||
.ThenInclude(b => b.Component)
|
.ThenInclude(b => b.Component)
|
||||||
.Select(b => b.GetViewModel)
|
.Select(b => b.GetViewModel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user