internal void AddOrder(int customerId, MyShoppingCartVM myCart, WebShopDBContext context) { DateTime timeStamp = DateTime.Now; Order.Add(new Order { DateTime = timeStamp, CustomerId = customerId }); SaveChanges(); int OID = Order.First(o => o.DateTime == timeStamp).Id; foreach (var article in myCart.Products) { for (int i = 0; i < article.NumberOfSameArticle; i++) { OrderArticles.Add(new OrderArticles { Oid = OID, ArticleNumber = $"{article.ArticleNrShort}{article.Size}", Price = article.Price }); SaveChanges(); } int currentQty = Product.First(p => p.ProdArtNr == $"{article.ArticleNrShort}{article.Size}").ProdQty; Product.First(p => p.ProdArtNr == $"{article.ArticleNrShort}{article.Size}").ProdQty = currentQty - article.NumberOfSameArticle; SaveChanges(); } ; User myUser = context.User.First(c => c.Id == customerId); EmailUtils.SendOrderConfEmail(OID, context, myUser); }