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); }
public IActionResult MyCart() { string[] tempArr = SessionUtils.GetArticleNumbersInCart(this); MyShoppingCartVM myCartVM = SessionUtils.GetArticles(this, webShopDBContext); if (User.Identity.IsAuthenticated) { myCartVM.IsLoggedIn = true; } return(View(myCartVM)); }
internal static MyShoppingCartVM GetArticles(Controller controller, WebShopDBContext context) { //int count = Convert.ToInt32(GetSessionCount(controller)); int count = Convert.ToInt32(GetSingleSessionCount(controller)); int totalCost = 0; int totalNumberOfProducts = 0; MyShoppingCartVM myCart = new MyShoppingCartVM(); List <ProductThumbnail> prodThumbList = new List <ProductThumbnail>(); string currentArtNr; if (count != 0) { for (int i = 0; i < count; i++) { string[] splitString = controller.HttpContext.Session.GetString(i.ToString()).Split(';'); currentArtNr = splitString[0]; Product currentProduct = context.Product.First(p => p.ProdArtNr == currentArtNr); totalCost += Convert.ToInt32(currentProduct.ProdPrice) * Convert.ToInt32(splitString[1]); totalNumberOfProducts += Convert.ToInt32(splitString[1]); Model currentModel = context.Model.First(m => m.ModelId == currentProduct.ProdModelId); Brand currentBrand = context.Brand.First(b => b.BrandId == currentProduct.ProdBrandId); Size currentSize = context.Size.First(s => s.SizeId == currentProduct.ProdSizeId); Color currentColor = context.Color.First(c => c.ColorId == currentProduct.ProdColorId); ProductThumbnail currentThumbnail = new ProductThumbnail { Brand = currentBrand.BrandName, Model = currentModel.ModelName, Price = Convert.ToInt32(currentProduct.ProdPrice), NumberOfSameArticle = Convert.ToInt32(splitString[1]), Size = currentSize.SizeName, Color = currentColor.ColorName, ImgPath = $"{currentProduct.ProdArtNr.Remove(currentProduct.ProdArtNr.Length - 2)}_1.jpg", ArticleNrShort = currentProduct.ProdArtNr.Substring(0, 5) }; prodThumbList.Add(currentThumbnail); } myCart.Products = prodThumbList.ToArray(); } myCart.TotalNumberOfProducts = totalNumberOfProducts; myCart.TotalCost = totalCost; return(myCart); }
public IActionResult GetCartPartial() { MyShoppingCartVM shoppingCart = SessionUtils.GetArticles(this, webShopDBContext); return(PartialView("_MyShoppingCartPartial", shoppingCart)); }