From 72aa20a1b3af9b854aaac349f93f394f93625e31 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Tue, 27 Feb 2024 16:23:02 +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=B1=D0=B0=D0=B3=D0=B0=20=D1=81=20?= =?UTF-8?q?=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20SushiName=20?= =?UTF-8?q?=D0=B2=20OrderViewModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 20 ++++++++++++------- .../SushiBarFileImplement/Models/Order.cs | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index 7d902cb..2d42369 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -15,7 +15,7 @@ namespace SushiBarFileImplement.Implements } public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList(); } public List GetFilteredList(OrderSearchModel model) { @@ -25,7 +25,7 @@ namespace SushiBarFileImplement.Implements } return source.Orders.Where(x => x.Id == model.Id).Select(x => - x.GetViewModel).ToList(); + AttachSushiName(x.GetViewModel)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -33,8 +33,8 @@ namespace SushiBarFileImplement.Implements { return null; } - return source.Orders.FirstOrDefault(x => - (x.Id == model.Id))?.GetViewModel; + return AttachSushiName(source.Orders.FirstOrDefault(x => + (x.Id == model.Id))?.GetViewModel); } public OrderViewModel? Insert(OrderBindingModel model) { @@ -46,7 +46,7 @@ namespace SushiBarFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return newOrder.GetViewModel; + return AttachSushiName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) { @@ -57,7 +57,7 @@ namespace SushiBarFileImplement.Implements } order.Update(model); source.SaveOrders(); - return order.GetViewModel; + return AttachSushiName(order.GetViewModel); } public OrderViewModel? Delete(OrderBindingModel model) { @@ -66,9 +66,15 @@ namespace SushiBarFileImplement.Implements { source.Orders.Remove(element); source.SaveOrders(); - return element.GetViewModel; + return AttachSushiName(element.GetViewModel); } return null; } + private OrderViewModel AttachSushiName(OrderViewModel model) + { + if (model == null) { return null; } + model.SushiName = source.Sushis.First(x => x.Id == model.SushiId).SushiName; + return model; + } } } diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index 4195407..6251638 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -45,7 +45,7 @@ namespace SushiBarFileImplement.Models } return new Order() { - Id = Convert.ToInt32(element.Attribute("id")!.Value), + Id = Convert.ToInt32(element.Attribute("Id")!.Value), SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),