From 74755b7b5d110946ad83bc2a496b542c0b912b1a Mon Sep 17 00:00:00 2001 From: kamilia Date: Sun, 19 May 2024 13:59:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B1=D1=8B=D1=82=D1=8C=20=D1=81=D1=87=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D0=BB=D0=B8=D0=B2=D0=BE=D0=B9=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B8=D0=BB=D0=BE=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractShopListImplement/OrderStorage.cs | 33 +++++++++++++++++-- .../Implements/OrderStorage.cs | 32 +++++++++++++++--- .../OrderStorage.cs | 26 ++++++++++++--- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs index 5f611de..1358529 100644 --- a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs +++ b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs @@ -66,7 +66,7 @@ namespace AircraftPlantListImplement.Implements return result; } - if (model.ClientId.HasValue && !model.Id.HasValue) + else if(model.ClientId.HasValue && !model.Id.HasValue) { foreach (var order in _source.Orders) { @@ -74,6 +74,27 @@ namespace AircraftPlantListImplement.Implements } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(GetViewModel(order)); + } + } + } + foreach (var order in _source.Orders) { if (order.Id == model.Id) @@ -90,7 +111,7 @@ namespace AircraftPlantListImplement.Implements /// public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -101,6 +122,14 @@ namespace AircraftPlantListImplement.Implements { return GetViewModel(order); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return GetViewModel(order); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return GetViewModel(order); + } } return null; } diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs index 745c49e..5431d1b 100644 --- a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs @@ -15,6 +15,7 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Plane) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -31,6 +32,7 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Client) .Include(x => x.Plane) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -41,22 +43,38 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Plane) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } - return context.Orders + else if (model.ImplementerId.HasValue) + { + return context.Orders .Include(x => x.Plane) .Include(x => x.Client) - .Where(x => x.Id == model.Id) + .Include(x => x.Implementer) + .Where(x => x.ImplementerId == model.ImplementerId) .Select(x => x.GetViewModel) .ToList(); + } + else if (model.Status != null) + { + return context.Orders + .Include(x => x.Plane) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -64,8 +82,12 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Plane) .Include(x => x.Client) - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? - .GetViewModel; + .Include(x => x.Implementer) + .FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs index f01c83a..b49e040 100644 --- a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs @@ -28,29 +28,47 @@ namespace AircraftPlantFileImplement.Implements { return new(); } - if (model.DateFrom.HasValue) + else if (model.DateFrom.HasValue) { return _source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)) .ToList(); } - if (model.ClientId.HasValue && !model.Id.HasValue) + else if (model.ClientId.HasValue && !model.Id.HasValue) { return _source.Orders .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return _source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return _source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - return GetViewModel(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); + var order = _source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? order.GetViewModel : null; } public OrderViewModel? Insert(OrderBindingModel model) {