fix
This commit is contained in:
parent
8203d22849
commit
ff2f0d57db
@ -8,7 +8,5 @@ namespace HardwareShopContracts.SearchModels
|
|||||||
public string? BuildName { get; set; } = string.Empty;
|
public string? BuildName { get; set; } = string.Empty;
|
||||||
|
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
|
|
||||||
public int? PurchaseId { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
{
|
{
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.Comments)
|
|
||||||
.Include(x => x.User)
|
.Include(x => x.User)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -24,17 +23,25 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
|
|
||||||
public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
|
public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.UserId.HasValue)
|
if (string.IsNullOrEmpty(model.BuildName) && !model.UserId.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
|
if (!string.IsNullOrEmpty(model.BuildName))
|
||||||
|
{
|
||||||
|
return context.Builds
|
||||||
|
.Include(x => x.Purchases)
|
||||||
|
.ThenInclude(x => x.Purchase)
|
||||||
|
.Include(x => x.BuildName.Contains(model.BuildName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.Comments)
|
.Include(x => x.UserId == model.UserId)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.UserId == model.UserId)
|
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -48,9 +55,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
}
|
}
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.Comments)
|
|
||||||
.Include(x => x.User)
|
.Include(x => x.User)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) ||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) ||
|
||||||
@ -69,9 +75,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
context.Builds.Add(newBuild);
|
context.Builds.Add(newBuild);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.Comments)
|
|
||||||
.Include(x => x.User)
|
.Include(x => x.User)
|
||||||
.Where(x => x.UserId == model.Id)
|
.Where(x => x.UserId == model.Id)
|
||||||
.FirstOrDefault(x => x.Id == newBuild.Id)
|
.FirstOrDefault(x => x.Id == newBuild.Id)
|
||||||
@ -85,9 +90,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var build = context.Builds
|
var build = context.Builds
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.Comments)
|
|
||||||
.Include(x => x.User)
|
.Include(x => x.User)
|
||||||
.Where(x => x.UserId == model.UserId)
|
.Where(x => x.UserId == model.UserId)
|
||||||
.FirstOrDefault(x => x.Id == model.Id);
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
@ -112,9 +116,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
{
|
{
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
var element = context.Builds
|
var element = context.Builds
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.Comments)
|
|
||||||
.Include(x => x.User)
|
.Include(x => x.User)
|
||||||
.Where(x => x.UserId == model.Id)
|
.Where(x => x.UserId == model.Id)
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
Loading…
Reference in New Issue
Block a user