From 07dc03d48a9eb34f5f8909ca01fccdb68cd0508e Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 10 Apr 2023 10:35:15 +0400 Subject: [PATCH] fix --- .../Implements/OrderStorage.cs | 14 ++++++++------ LawFirm/LawFirmDatabaseImplement/Models/Order.cs | 5 ++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/LawFirm/LawFirmDatabaseImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmDatabaseImplement/Implements/OrderStorage.cs index 539f9f3..fd51903 100644 --- a/LawFirm/LawFirmDatabaseImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmDatabaseImplement/Implements/OrderStorage.cs @@ -21,7 +21,7 @@ namespace LawFirmDatabaseImplement.Implements return null; } using var context = new LawFirmDatabase(); - return context.Orders.Include(x => x.Document).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) @@ -34,13 +34,15 @@ namespace LawFirmDatabaseImplement.Implements if (model.ClientId.HasValue) { return context.Orders - .Include(x => x.Client) + .Include(x => x.Document) + .Include(x => x.Client) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } return context.Orders - .Include(x => x.Document) + .Include(x => x.Client) + .Include(x => x.Document) .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -49,7 +51,7 @@ namespace LawFirmDatabaseImplement.Implements public List GetFullList() { using var context = new LawFirmDatabase(); - return context.Orders.Include(x => x.Document).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Document).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -62,7 +64,7 @@ namespace LawFirmDatabaseImplement.Implements using var context = new LawFirmDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -75,7 +77,7 @@ namespace LawFirmDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs index e590903..44efe35 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs @@ -63,7 +63,6 @@ namespace LawFirmDatabaseImplement.Models public OrderViewModel GetViewModel { get { - var context = new LawFirmDatabase(); return new () { @@ -75,8 +74,8 @@ namespace LawFirmDatabaseImplement.Models DateImplement = DateImplement, Id = Id, Status = Status, - DocumentName = context.Documents.FirstOrDefault(x => x.Id == DocumentId)?.DocumentName ?? string.Empty, - ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty + DocumentName = Document.DocumentName, + ClientFIO = Client.ClientFIO }; } }