public OrderController(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, IdentityDbContext identityDbContext, WebShopDBContext webShopDBContext) { this.userManager = userManager; this.signInManager = signInManager; this.identityDbContext = identityDbContext; this.webShopDBContext = webShopDBContext; }
public static void SendOrderConfEmail(int orderNumber, WebShopDBContext context, User user) { OrderArticles[] myArticles = context.OrderArticles.Where(o => o.Oid == orderNumber).ToArray(); Product[] myProducts = new Product[myArticles.Length]; for (int i = 0; i < myArticles.Length; i++) { myProducts[i] = context.Product.First(p => p.ProdArtNr == myArticles[i].ArticleNumber); } string[] myarticlesStrings = new string[myArticles.Length]; for (int i = 0; i < myArticles.Length; i++) { string brandName = context.Brand.First(b => b.BrandId == myProducts[i].ProdBrandId).BrandName; string modelName = context.Model.First(b => b.ModelId == myProducts[i].ProdModelId).ModelName; string sizeName = context.Size.First(b => b.SizeId == myProducts[i].ProdSizeId).SizeName; string colorName = context.Color.First(b => b.ColorId == myProducts[i].ProdColorId).ColorName; myarticlesStrings[i] = $"Artikel nr: {myArticles[i].ArticleNumber}, {brandName} {modelName}, {colorName}, {sizeName}, {myArticles[i].Price} kr"; } toAddress = new MailAddress(user.Email, user.Firstname); subject = $"Orderbekräftelse"; body = $"Tack för din order, {user.Firstname}. \nNedan följer en sammanfattning av din order (ordernr: {orderNumber}). \n"; foreach (var item in myarticlesStrings) { body += $"{item} \n"; } body += "\nSkulle det vara något som inte stämmer, vänligen kontakta vår kundservice. \n \nMed vänliga hälsningar, \nFMC Webshop"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(fromAddress.Address, fromPassword), Timeout = 20000 }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } }
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 static void AddToCart(ProductController controller, ProductProductItemVM prodItemVM, WebShopDBContext webShopDBContext) { string index = "-1"; for (int i = 0; i < 20; i++) { if (controller.HttpContext.Session.GetString(i.ToString()) == null) { index = i.ToString(); break; } } string size = webShopDBContext.Size.First(s => s.SizeId == Convert.ToInt32(prodItemVM.SelectedSize)).SizeName; string artNr = $"{prodItemVM.ArticleNum}{size}"; int indexOfArticle = SessionUtils.GetSessionIndex(controller, artNr); bool isInStock = webShopDBContext.CheckIfInStock(indexOfArticle.ToString(), controller); if (isInStock) { if (index == "-1") { } else { int numberOfSame = SessionUtils.GetSessionIndex(controller, artNr); if (numberOfSame == -1) { string sessionString = $"{artNr};1"; controller.HttpContext.Session.SetString(index, sessionString); } else { string[] splitt = controller.HttpContext.Session.GetString(numberOfSame.ToString()).Split(';'); int numberOfArt = Convert.ToInt32(splitt[1]); int newNumberOfArt = ++numberOfArt; string sessionString = $"{artNr};{newNumberOfArt}"; controller.HttpContext.Session.SetString(numberOfSame.ToString(), sessionString); } } } }
public ShoeRepository(WebShopDBContext context) { _context = context; }
internal static void EditProduct(OrderController orderController, string artNr, string size, int plusOrMinus, WebShopDBContext context) { string[] articlesInCart = GetArticleNumbersInCart(orderController); string article = articlesInCart.First(a => a.StartsWith($"{artNr}{size}")); string[] articleSplit = article.Split(';'); int sessionKey = GetSessionIndex(orderController, articleSplit[0]); if (articleSplit[1] == "1" && plusOrMinus == 1) { int totalRows = Convert.ToInt32(GetSingleSessionCount(orderController)); orderController.HttpContext.Session.Remove(sessionKey.ToString()); UpdateCartSessions(orderController, sessionKey, totalRows); } else { int count = Convert.ToInt32(articleSplit[1]); if (plusOrMinus == 1) // Ta bort EN produkt { count--; } else if (plusOrMinus == 2 && (context.CheckIfInStock(sessionKey.ToString(), orderController))) // Lägg till EN produkt { count++; } string newArticleString = $"{articleSplit[0]};{count.ToString()}"; orderController.HttpContext.Session.SetString(sessionKey.ToString(), newArticleString); } }