From 2feb8c0a7886b31373b489d8332b048d316e31f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Mon, 27 Mar 2023 17:58:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B5=D0=B1=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=81=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8E=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?,=20=D0=BB=D1=83=D1=87=D1=88=D0=B5=20=D0=BF=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=BD=D0=BE,=20=D1=87=D0=B5=D0=BC=20=D0=BD=D0=B8=D0=BA=D0=BE?= =?UTF-8?q?=D0=B3=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 21 +++++++++---- .../Implements/OrderStorage.cs | 15 ++++++++-- .../Implements/OrderStorage.cs | 30 ++++++++++++++----- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs index 59a09f9..a5c29f5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs @@ -24,15 +24,26 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return new(); } using var context = new BlacksmithWorkshopDatabase(); - List orderList = context.Orders - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + List orderList = new(); + if (model.Id.HasValue) //сначала ищем по Id + { + orderList = context.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue) //если у модели нет Id, ищем по датам + { + orderList = context.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } foreach (var order in orderList) { string manufactureName = context.Manufactures diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index 4715a2d..d37e815 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -27,14 +27,25 @@ namespace BlacksmithWorkshopFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return new(); } - return source.Orders + if (model.Id.HasValue)//сначала ищем по Id + { + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => AddManufactureName(x.GetViewModel)) + .ToList(); + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если Id в модели нет, ищем по датам + { + return source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => AddManufactureName(x.GetViewModel)) .ToList(); + } + return new();//если нет ни того, ни другого, возвращаем пустой список } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 1753e42..3246ce6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -28,18 +28,34 @@ namespace BlacksmithWorkshopListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return result; } - foreach (var order in _source.Orders) + if (model.Id.HasValue)//сначала ищем по Id { - if (model.Id.HasValue && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + foreach (var order in _source.Orders) { - OrderViewModel vm = order.GetViewModel; - var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); - vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; - result.Add(vm); + if (model.Id == order.Id) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); + } + } + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если у модели нет Id, ищем по датам + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); + } } } return result; -- 2.25.1