From 6d197bee0cb7005f70fa14bf75701df22fae64b0 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 20:59:47 +0400 Subject: [PATCH 1/2] lab-3 is it finish? --- .../Implements/OrderStorage.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index f489a4e..58abc02 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -30,6 +30,7 @@ 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(); @@ -41,7 +42,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return null; } using var context = new BlacksmithWorkshopDataBase(); - return context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -58,8 +61,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var order = context.Orders.FirstOrDefault(x => x.Id == - model.Id); + var order = context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -71,8 +75,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == - model.Id); + var element = context.Orders + .Include(x => x.Manufacture) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); From 51c263ca230fd2296f14d941d3e0bfb262fe37bc Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 25 Mar 2024 21:46:50 +0400 Subject: [PATCH 2/2] lab-3 it is finish --- ...Designer.cs => 20240325174141_InitialCreate.Designer.cs} | 2 +- ...611_InitialCreate.cs => 20240325174141_InitialCreate.cs} | 0 .../BlacksmithWorkshopDatabaseImplement/Models/Order.cs | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240324164611_InitialCreate.Designer.cs => 20240325174141_InitialCreate.Designer.cs} (99%) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240324164611_InitialCreate.cs => 20240325174141_InitialCreate.cs} (100%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs similarity index 99% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs index 1629012..4643766 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240324164611_InitialCreate")] + [Migration("20240325174141_InitialCreate")] partial class InitialCreate { /// diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs similarity index 100% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240325174141_InitialCreate.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 8a5b48d..4d6fd5b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -25,9 +25,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [Required] public int ManufactureId { get; private set; } - public virtual Manufacture Manufacture { get; set; } = new(); + public virtual Manufacture? Manufacture { get; set; } - public static Order? Create(OrderBindingModel model) + public static Order Create(OrderBindingModel model) { return new Order() { @@ -52,7 +52,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public OrderViewModel GetViewModel => new() { ManufactureId = ManufactureId, - ManufactureName = Manufacture.ManufactureName, + ManufactureName = Manufacture?.ManufactureName ?? string.Empty, Count = Count, Sum = Sum, Status = Status,