сборки с продавцами

This commit is contained in:
bekodeg 2024-05-01 12:25:11 +04:00
parent 7f6c134c57
commit c2c4759c68
3 changed files with 13 additions and 2 deletions

View File

@ -3,6 +3,7 @@
public class BuildSearchModel public class BuildSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int VendorId { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public int? VendorId { get; set; } public int? VendorId { get; set; }
} }

View File

@ -4,7 +4,7 @@
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public int? VendorId { get; set; } public int VendorId { get; set; }
public int? Build { get; set; } public List<int>? Builds { get; set; }
} }
} }

View File

@ -16,6 +16,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Comments) .Include(b => b.Comments)
.Include(b => b.Components) .Include(b => b.Components)
.ThenInclude(b => b.Component) .ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Select(b => b.GetViewModel) .Select(b => b.GetViewModel)
.ToList(); .ToList();
} }
@ -28,6 +29,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
} }
using var context = new ComputerHardwareStoreDBContext(); using var context = new ComputerHardwareStoreDBContext();
return context.Builds return context.Builds
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.VendorId )
.Where(b => b.Name.Contains(model.Name)) .Where(b => b.Name.Contains(model.Name))
.Include(b => b.Comments) .Include(b => b.Comments)
.Include(b => b.Components) .Include(b => b.Components)
@ -44,6 +47,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
} }
using var context = new ComputerHardwareStoreDBContext(); using var context = new ComputerHardwareStoreDBContext();
return context.Builds return context.Builds
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.VendorId)
.Include(b => b.Comments) .Include(b => b.Comments)
.Include(b => b.Components) .Include(b => b.Components)
.ThenInclude(b => b.Component) .ThenInclude(b => b.Component)
@ -64,6 +69,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
context.Builds.Add(newBuild); context.Builds.Add(newBuild);
context.SaveChanges(); context.SaveChanges();
return context.Builds return context.Builds
.Include(b => b.Vendor)
.Include(b => b.Comments) .Include(b => b.Comments)
.Include(b => b.Components) .Include(b => b.Components)
.ThenInclude(b => b.Component) .ThenInclude(b => b.Component)
@ -78,6 +84,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Comments) .Include(b => b.Comments)
.Include(b => b.Components) .Include(b => b.Components)
.ThenInclude(b => b.Component) .ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.FirstOrDefault(p => p.Id == model.Id); .FirstOrDefault(p => p.Id == model.Id);
if (build == null) if (build == null)
{ {
@ -94,6 +102,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Comments) .Include(b => b.Comments)
.Include(b => b.Components) .Include(b => b.Components)
.ThenInclude(b => b.Component) .ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.FirstOrDefault(p => p.Id == model.Id); .FirstOrDefault(p => p.Id == model.Id);
if (build == null) if (build == null)
{ {