поиск сборок по продукту
This commit is contained in:
parent
80f5b2fde7
commit
c229b58d9d
@ -4,7 +4,7 @@
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int VendorId { get; set; }
|
||||
public List<int>? Builds { get; set; }
|
||||
public int StoreKeeperId { get; set; }
|
||||
public int? BuildId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
int StoreKeeperId { get; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -20,6 +20,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<BuildComponent> BuldComponents { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -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<int, (IComponentModel, int)>? _productComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
|
Loading…
Reference in New Issue
Block a user