Eliseev E.E. LabWork03 #4

Closed
ElEgEv wants to merge 12 commits from LabWork03 into LabWork02
Showing only changes of commit 6b5b1ec34d - Show all commits

View File

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