From ea0dabdb4c1bca184fafc0992628b3ef8f516440 Mon Sep 17 00:00:00 2001 From: Safgerd Date: Thu, 20 Apr 2023 20:49:48 +0400 Subject: [PATCH] =?UTF-8?q?LabWork05=5FBase:=20=D0=A4=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 26 ++++++++++--------- .../Models/Order.cs | 5 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs index 8bb101d..0e0928c 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs @@ -21,8 +21,8 @@ namespace AutomobilePlantDatabaseImplement.Implements return null; } using var context = new AutomobilePlantDatabase(); - return context.Orders.Include(x => x.Car).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } + return context.Orders.Include(x => x.Car).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } public List GetFilteredList(OrderSearchModel model) { @@ -34,14 +34,16 @@ namespace AutomobilePlantDatabaseImplement.Implements if (model.ClientId.HasValue) { return context.Orders - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) + .Include(x => x.Car) + .Include(x => x.Client) + .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } return context.Orders - .Include(x => x.Car) - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + .Include(x => x.Client) + .Include(x => x.Car) + .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); } @@ -49,8 +51,8 @@ namespace AutomobilePlantDatabaseImplement.Implements public List GetFullList() { using var context = new AutomobilePlantDatabase(); - return context.Orders.Include(x => x.Car).Select(x => x.GetViewModel).ToList(); - } + return context.Orders.Include(x => x.Car).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + } public OrderViewModel? Insert(OrderBindingModel model) { @@ -62,8 +64,8 @@ namespace AutomobilePlantDatabaseImplement.Implements using var context = new AutomobilePlantDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Car).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; - } + return context.Orders.Include(x => x.Car).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + } public OrderViewModel? Update(OrderBindingModel model) { @@ -75,8 +77,8 @@ namespace AutomobilePlantDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Car).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; - } + return context.Orders.Include(x => x.Car).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new AutomobilePlantDatabase(); diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs index 7466161..58593c0 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs @@ -67,7 +67,6 @@ namespace AutomobilePlantDatabaseImplement.Models { get { - var context = new AutomobilePlantDatabase(); return new() { @@ -79,8 +78,8 @@ namespace AutomobilePlantDatabaseImplement.Models DateImplement = DateImplement, Id = Id, Status = Status, - CarName = context.Cars.FirstOrDefault(x => x.Id == CarId)?.CarName ?? string.Empty, - ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty + CarName = Car.CarName, + ClientFIO = Client.ClientFIO }; } }