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

View File

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