ProductFix

This commit is contained in:
Sergey Kozyrev 2024-05-01 15:44:39 +04:00
parent 0c4da70df3
commit 23b5ce0cdd
2 changed files with 6 additions and 3 deletions

View File

@ -13,5 +13,6 @@ namespace Contracts.SearchModels
public int? UserId { get; set; } public int? UserId { get; set; }
public int? MachineId { get; set; } public int? MachineId { get; set; }
public int? WorkerId { get; set; } public int? WorkerId { get; set; }
public int? DetailId { get; set; }
} }
} }

View File

@ -29,13 +29,15 @@ namespace DatabaseImplement.Implements
public List<ProductViewModel> GetFilteredList(ProductSearchModel model) public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{ {
if (!model.UserId.HasValue && !model.WorkerId.HasValue) if (!model.UserId.HasValue && !model.WorkerId.HasValue && !model.DetailId.HasValue)
{ {
return new(); return new();
} }
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
if (model.WorkerId.HasValue) if (model.DetailId.HasValue)
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.WorkerId) != null).Select(x => x.GetViewModel).ToList(); return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Select(x => x.GetViewModel).ToList();
else if (model.WorkerId.HasValue)
return context.Products.Where(p => p.MachineId.HasValue).Include(p => p.Machine).ThenInclude(p => p.Workers).Where(x => x.Machine.Workers.FirstOrDefault(y => y.WorkerId == model.WorkerId) != null).Select(x => x.GetViewModel).ToList();
else else
return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList();
} }