финал

This commit is contained in:
GokaPek 2024-03-27 10:54:50 +04:00
parent 41531f9761
commit e184ca408d
2 changed files with 9 additions and 10 deletions

View File

@ -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<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -49,6 +47,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements
using var context = new AbstractLawFirmDataBase();
return context.Orders
.Where(x => x.Id == model.Id)
.Include(x => x.Document)
.Select(x => x.GetViewModel)
.ToList();
}
@ -56,9 +55,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements
public List<OrderViewModel> 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;
}
}
}

View File

@ -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,