diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs index 52f2afa..ae14a74 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs @@ -35,9 +35,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements return null; } using var context = new AbstractLawFirmDataBase(); - return context.Orders - .FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Document).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) @@ -49,16 +47,15 @@ namespace AbstractLawFirmDatabaseImplement.Implements using var context = new AbstractLawFirmDataBase(); return context.Orders .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Document) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new AbstractLawFirmDataBase(); - return context.Orders - .Select(x => x.GetViewModel) - .ToList(); + return context.Orders.Include(x => x.Document).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -71,7 +68,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements using var context = new AbstractLawFirmDataBase(); context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -84,7 +81,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements } component.Update(model); context.SaveChanges(); - return component.GetViewModel; + return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs index f875f25..6a8b77a 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace AbstractLawFirmDataBaseImplement.Models { public int Id { get; private set; } public int DocumentId { get; private set; } + public virtual Document? Document { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -54,6 +55,7 @@ namespace AbstractLawFirmDataBaseImplement.Models { Id = Id, DocumentId = DocumentId, + DocumentName = Document.DocumentName, Count = Count, Sum = Sum, Status = Status,