Eliseev E.E. LabWork03 #4
@ -55,38 +55,19 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
|
||||
return context.Orders
|
||||
.Include(x => x.Manufacture)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
var element = context.Manufactures
|
||||
.FirstOrDefault(x => x.Id == order.ManufactureId);
|
||||
viewModel.ManufactureName = element.ManufactureName;
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
|
||||
return context.Orders
|
||||
.Select(x => new OrderViewModel
|
||||
{
|
||||
Id = x.Id,
|
||||
ManufactureId = x.ManufactureId,
|
||||
Count = x.Count,
|
||||
Sum = x.Sum,
|
||||
Status = x.Status,
|
||||
DateCreate = x.DateCreate,
|
||||
DateImplement = x.DateImplement,
|
||||
ManufactureName = x.Manufacture.ManufactureName
|
||||
})
|
||||
.Include(x => x.Manufacture)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -103,7 +84,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
return newOrder.GetViewModel;
|
||||
return context.Orders.Include(x => x.Manufacture)
|
||||
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
|
Loading…
Reference in New Issue
Block a user