From 1a41ad5ce320ff201b5314a425d103597c17b150 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 28 Feb 2023 12:38:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B6=D0=B5=D1=82=20=D0=B1=D1=8B?= =?UTF-8?q?=D1=82=D1=8C=20=D1=82=D0=B0=D0=BA=20=D0=B1=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BB=D1=83=D1=87=D1=88=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 18 +++++------------- .../SushiBarDatabaseImplement/Models/Order.cs | 3 ++- .../SushiBarDatabase.cs | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index d451de5..41fcc45 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; @@ -49,18 +50,9 @@ namespace SushiBarDatabaseImplement.Implements { using var context = new SushiBarDatabase(); return context.Orders - .Select(x => new OrderViewModel - { - Id = x.Id, - SushiId = x.SushiId, - Count = x.Count, - Sum = x.Sum, - Status = x.Status, - DateCreate = x.DateCreate, - DateImplement = x.DateImplement, - SushiName = x.Sushi.SushiName - }) - .ToList(); + .Include(x => x.Sushi) + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index aac6f84..5e3bac7 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -20,7 +20,7 @@ namespace SushiBarDatabaseImplement.Models public DateTime DateCreate { get; set; } public DateTime? DateImplement { get; set; } public int Id { get; set; } - public virtual Sushi Sushi { get; set; } + public Sushi Sushi { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -59,6 +59,7 @@ namespace SushiBarDatabaseImplement.Models DateImplement = DateImplement, Id = Id, Status = Status, + SushiName = Sushi.SushiName, }; } } diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 58f8313..84da6c9 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -9,7 +9,7 @@ namespace SushiBarDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-JC256C6\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); }