Compare commits

..

No commits in common. "db1db180b696295e1f5d67ae2ac60c1da1d47b34" and "cb29ffb24cf8002679c6cb1b8c910fd8de6ba858" have entirely different histories.

2 changed files with 10 additions and 13 deletions

View File

@ -43,7 +43,6 @@ namespace AutomobilePlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer) .Include(x => x.Implementer)
.Include(x => x.Car)
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -51,7 +50,6 @@ namespace AutomobilePlantDatabaseImplement.Implements
if (model.Statuses != null) if (model.Statuses != null)
{ {
return context.Orders return context.Orders
.Include(x => x.Car)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer) .Include(x => x.Implementer)
.Where(x => model.Statuses.Contains(x.Status)) .Where(x => model.Statuses.Contains(x.Status))
@ -60,7 +58,6 @@ namespace AutomobilePlantDatabaseImplement.Implements
} }
return context.Orders return context.Orders
.Include(x => x.Car) .Include(x => x.Car)
.Include(x => x.Client)
.Include(x => x.Implementer) .Include(x => x.Implementer)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -70,7 +67,7 @@ namespace AutomobilePlantDatabaseImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new AutomobilePlantDatabase(); using var context = new AutomobilePlantDatabase();
return context.Orders.Include(x => x.Car).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); return context.Orders.Include(x => x.Car).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
@ -83,7 +80,7 @@ namespace AutomobilePlantDatabaseImplement.Implements
using var context = new AutomobilePlantDatabase(); using var context = new AutomobilePlantDatabase();
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Car).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; return context.Orders.Include(x => x.Car).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
@ -96,13 +93,12 @@ namespace AutomobilePlantDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Car).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders.Include(x => x.Car).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
{ {
using var context = new AutomobilePlantDatabase(); using var context = new AutomobilePlantDatabase();
var element = context.Orders var element = context.Orders
.Include(x => x.Car)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer) .Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id); .FirstOrDefault(x => x.Id == model.Id);

View File

@ -71,6 +71,7 @@ namespace AutomobilePlantDatabaseImplement.Models
{ {
get get
{ {
var context = new AutomobilePlantDatabase();
return new() return new()
{ {
@ -83,9 +84,9 @@ namespace AutomobilePlantDatabaseImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
Id = Id, Id = Id,
Status = Status, Status = Status,
CarName = Car.CarName, CarName = context.Cars.FirstOrDefault(x => x.Id == CarId)?.CarName ?? string.Empty,
ClientFIO = Client.ClientFIO, ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ImplementerFIO = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
}; };
} }
} }