Compare commits

...

2 Commits

Author SHA1 Message Date
db1db180b6 Merge lab5base fix into lab6base 2023-04-20 21:11:54 +04:00
ea0dabdb4c LabWork05_Base: Фикс 2023-04-20 20:49:48 +04:00
2 changed files with 13 additions and 10 deletions

View File

@ -43,6 +43,7 @@ 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();
@ -50,6 +51,7 @@ 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))
@ -58,6 +60,7 @@ 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)
@ -67,7 +70,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.Implementer).Select(x => x.GetViewModel).ToList(); return context.Orders.Include(x => x.Car).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
@ -80,8 +83,8 @@ 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).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; return context.Orders.Include(x => x.Car).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
@ -93,13 +96,14 @@ namespace AutomobilePlantDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Car).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders.Include(x => x.Car).Include(x => x.Client).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.Client) .Include(x => x.Car)
.Include(x => x.Client)
.Include(x => x.Implementer) .Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id); .FirstOrDefault(x => x.Id == model.Id);
if (element != null) if (element != null)

View File

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