public void AddOrder(order o, IEnumerable<orderproduct> product)
{
context.orders.Add(o);
context.SaveChanges();
decimal total = 0;
//добовляем сгенерированый ID
foreach (var item in product)
{
item.Id_Order = o.Id_Order;
if (o.id_IngridientsBuyer == 1) // повар
{
total += item.Price;
}
else
{
total += item.PriceWithIngridients==null?0:(decimal)item.PriceWithIngridients;
}
}
o.total = total;
context.orderproducts.AddRange(product);
context.SaveChanges();
}