From e47a130624c6e6195d53ab4cd34fabe1f844be74 Mon Sep 17 00:00:00 2001 From: goldfest Date: Thu, 2 May 2024 15:03:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D1=80=D0=B5=D0=B4=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20fileImplemen?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/TravelCompany/TravelCompanyFileImplement/Implements/OrderStorage.cs b/TravelCompany/TravelCompanyFileImplement/Implements/OrderStorage.cs index 8ea5ea9..bd65bc6 100644 --- a/TravelCompany/TravelCompanyFileImplement/Implements/OrderStorage.cs +++ b/TravelCompany/TravelCompanyFileImplement/Implements/OrderStorage.cs @@ -22,7 +22,7 @@ namespace TravelCompanyFileImplement.Implements public List GetFullList() { return source.Orders - .Select(x => AccessTravelStorage(x.GetViewModel)) + .Select(x => AccessStorage(x.GetViewModel)) .ToList(); } @@ -36,9 +36,11 @@ model) (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && (!model.ClientId.HasValue || x.ClientId == model.ClientId) + && + (!model.Status.HasValue || x.Status == model.Status) ) ) - .Select(x => AccessTravelStorage(x.GetViewModel)) + .Select(x => AccessStorage(x.GetViewModel)) .ToList(); } @@ -48,8 +50,11 @@ model) { return null; } - return AccessTravelStorage(source.Orders - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel); + return AccessStorage(source.Orders + .FirstOrDefault( + x => ((model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel); } public OrderViewModel? Insert(OrderBindingModel model) @@ -62,7 +67,7 @@ model) } source.Orders.Add(newOrder); source.SaveOrders(); - return AccessTravelStorage(newOrder.GetViewModel); + return AccessStorage(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -74,7 +79,7 @@ model) } order.Update(model); source.SaveOrders(); - return AccessTravelStorage(order.GetViewModel); + return AccessStorage(order.GetViewModel); } public OrderViewModel? Delete(OrderBindingModel model) { @@ -84,33 +89,24 @@ model) { source.Orders.Remove(element); source.SaveOrders(); - return AccessTravelStorage(element.GetViewModel); + return AccessStorage(element.GetViewModel); } return null; } - public OrderViewModel AccessTravelStorage(OrderViewModel model) - { - if (model == null) - return null; - foreach (var Travel in source.Travels) - { - if (Travel.Id == model.TravelId) - { - model.TravelName = Travel.TravelName; - break; - } - } - return model; - } - - public OrderViewModel AccessClientStorage(OrderViewModel model) + public OrderViewModel AccessStorage(OrderViewModel model) { if (model == null) return null; + var iceCream = source.Travels.FirstOrDefault(x => x.Id == model.Id); var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (iceCream != null) + model.TravelName = iceCream.TravelName; if (client != null) model.ClientFIO = client.ClientFIO; + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } }