From 95ed066239876ea98dfca7bded20596947366b03 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 30 Apr 2024 21:51:49 +0400 Subject: [PATCH] ReportFirst Work it harder, make it Do it faster, makes us More than ever, hour after hour Work is never over --- Course/Contracts/SearchModels/ProductSearchModel.cs | 1 + Course/Contracts/SearchModels/ProductionSearchModel.cs | 1 + Course/DatabaseImplement/Implements/ProductStorage.cs | 7 +++++-- Course/DatabaseImplement/Implements/ProductionStorage.cs | 7 +++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Course/Contracts/SearchModels/ProductSearchModel.cs b/Course/Contracts/SearchModels/ProductSearchModel.cs index 5f6bdae..296327b 100644 --- a/Course/Contracts/SearchModels/ProductSearchModel.cs +++ b/Course/Contracts/SearchModels/ProductSearchModel.cs @@ -12,5 +12,6 @@ namespace Contracts.SearchModels public string? Name { get; set; } public int? UserId { get; set; } public int? MachineId { get; set; } + public int? DetailId { get; set; } } } diff --git a/Course/Contracts/SearchModels/ProductionSearchModel.cs b/Course/Contracts/SearchModels/ProductionSearchModel.cs index bf5ff28..825d1c6 100644 --- a/Course/Contracts/SearchModels/ProductionSearchModel.cs +++ b/Course/Contracts/SearchModels/ProductionSearchModel.cs @@ -11,5 +11,6 @@ namespace Contracts.SearchModels public int? Id { get; set; } public string? Name { get; set; } public int? UserId { get; set; } + public int? DetailId { get; set; } } } diff --git a/Course/DatabaseImplement/Implements/ProductStorage.cs b/Course/DatabaseImplement/Implements/ProductStorage.cs index 0be01eb..59c0631 100644 --- a/Course/DatabaseImplement/Implements/ProductStorage.cs +++ b/Course/DatabaseImplement/Implements/ProductStorage.cs @@ -29,12 +29,15 @@ namespace DatabaseImplement.Implements public List GetFilteredList(ProductSearchModel model) { - if (!model.UserId.HasValue) + if (!model.UserId.HasValue && !model.DetailId.HasValue) { return new(); } using var context = new FactoryGoWorkDatabase(); - return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).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 + return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Course/DatabaseImplement/Implements/ProductionStorage.cs b/Course/DatabaseImplement/Implements/ProductionStorage.cs index 901fdbb..c1a4a2f 100644 --- a/Course/DatabaseImplement/Implements/ProductionStorage.cs +++ b/Course/DatabaseImplement/Implements/ProductionStorage.cs @@ -29,12 +29,15 @@ namespace DatabaseImplement.Implements public List GetFilteredList(ProductionSearchModel model) { - if (!model.UserId.HasValue) + if (!model.UserId.HasValue && !model.DetailId.HasValue) { return new(); } using var context = new FactoryGoWorkDatabase(); - return context.Productions.Include(x => x.Details).ThenInclude(x => x.Detail).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); + if (model.DetailId.HasValue) + return context.Productions.Include(x => x.Details).ThenInclude(x => x.Detail).Where(x => x.UserId == model.UserId).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Include(x => x.User).Select(x => x.GetViewModel).ToList(); + else + return context.Productions.Include(x => x.Details).ThenInclude(x => x.Detail).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); } public List GetFullList()