From 23b5ce0cdd64bc799a34dc565c1dcc0c476bb7f2 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Wed, 1 May 2024 15:44:39 +0400 Subject: [PATCH] ProductFix --- Course/Contracts/SearchModels/ProductSearchModel.cs | 1 + Course/DatabaseImplement/Implements/ProductStorage.cs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Course/Contracts/SearchModels/ProductSearchModel.cs b/Course/Contracts/SearchModels/ProductSearchModel.cs index 57ec6cf..457497e 100644 --- a/Course/Contracts/SearchModels/ProductSearchModel.cs +++ b/Course/Contracts/SearchModels/ProductSearchModel.cs @@ -13,5 +13,6 @@ namespace Contracts.SearchModels public int? UserId { get; set; } public int? MachineId { get; set; } public int? WorkerId { get; set; } + public int? DetailId { get; set; } } } diff --git a/Course/DatabaseImplement/Implements/ProductStorage.cs b/Course/DatabaseImplement/Implements/ProductStorage.cs index 1622719..93ad8c6 100644 --- a/Course/DatabaseImplement/Implements/ProductStorage.cs +++ b/Course/DatabaseImplement/Implements/ProductStorage.cs @@ -29,13 +29,15 @@ namespace DatabaseImplement.Implements public List GetFilteredList(ProductSearchModel model) { - if (!model.UserId.HasValue && !model.WorkerId.HasValue) + if (!model.UserId.HasValue && !model.WorkerId.HasValue && !model.DetailId.HasValue) { return new(); } using var context = new FactoryGoWorkDatabase(); - if (model.WorkerId.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(); + 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.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 return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); }