From 6b5b1ec34dc30850f1c96b6062597e9734c80a02 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 23:46:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B7=D0=B0=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=BD=D0=BE=D0=B5=20=D0=B8=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index 8dfa776..d9366e5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -55,38 +55,19 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements using var context = new BlacksmithWorkshopDatabase(); return context.Orders + .Include(x => x.Manufacture) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); } - private static OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - using var context = new BlacksmithWorkshopDatabase(); - var element = context.Manufactures - .FirstOrDefault(x => x.Id == order.ManufactureId); - viewModel.ManufactureName = element.ManufactureName; - - return viewModel; - } - public List GetFullList() { using var context = new BlacksmithWorkshopDatabase(); return context.Orders - .Select(x => new OrderViewModel - { - Id = x.Id, - ManufactureId = x.ManufactureId, - Count = x.Count, - Sum = x.Sum, - Status = x.Status, - DateCreate = x.DateCreate, - DateImplement = x.DateImplement, - ManufactureName = x.Manufacture.ManufactureName - }) + .Include(x => x.Manufacture) + .Select(x => x.GetViewModel) .ToList(); } @@ -103,7 +84,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders.Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model)