From 867b5507db30a1848d1a2920ac77080b5247bb64 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 23:30:35 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopDatabaseImplement/Models/Order.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index dd91c74..696dd3f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -4,6 +4,7 @@ using BlacksmithWorkshopDataModels.Enums; using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,14 +16,19 @@ namespace BlacksmithWorkshopDatabaseImplement.Models { public int Id { get; private set; } + [Required] public int ManufactureId { get; private set; } + [Required] public int Count { get; private set; } + [Required] public double Sum { get; private set; } + [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } From 6b5b1ec34dc30850f1c96b6062597e9734c80a02 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 23:46:10 +0400 Subject: [PATCH 2/3] =?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) From d5a8e38d9e3cc5c17484186591bcf5caf40693ce Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 23:59:44 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9E=D1=87=D0=B5=D1=80=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B2=D0=B0=D0=B6=D0=BD=D0=BE=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=B2=D1=88?= =?UTF-8?q?=D0=B5=D0=B5=D1=81=D1=8F=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopDatabaseImplement/Models/Order.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 696dd3f..b99055e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -74,7 +74,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ManufactureName = Manufacture.ManufactureName }; } }