public ActionResult AddProductToShoppingbag(ulong productId) { CheckSession(); if (TempData["ErrorMessage"] != null) { ViewBag.Error = TempData["ErrorMessage"].ToString(); } bool amountChanged = false; Session ses = ((Session)this.Session["__MySessionObject"]); foreach (OrderLine ol in ses.ShoppingBag.OrderLines) { if (ol.Product.Id == productId) { ol.Amount++; amountChanged = true; } } if (!amountChanged) { using (DatabaseQuery query = new DatabaseQuery()) { Product product = query.GetProduct(productId); OrderLine ol = new OrderLine(); ol.Product = product; ol.Amount = 1; ses.ShoppingBag.OrderLines.Add(ol); } } this.Session["__MySessionObject"] = ses; return RedirectToAction("Products", "Home"); }
//nullable int public ActionResult Make_Order(ulong? Id) { if (Id != null) { ulong productId = (ulong)Id; using (DatabaseQuery productQuerry = new DatabaseQuery()) { Product product = productQuerry.GetProduct(productId); if (product != null) //ALs er een product is { Session session = (Session)this.Session["__MySessionObject"]; { using (DatabaseQuery purcasheQuery = new DatabaseQuery()) { //Maak een purchase SQL query } RedirectToAction("ProductAdded", "Home"); } } else //Redirect naar de home anlshet niet lukt { RedirectToAction("Login", "home"); } } } return RedirectToAction("Index", "Home"); //als het wel lukt dan redirect je naar home }
public ActionResult Preview(ulong productId) { CheckSession(); using (DatabaseQuery querry = new DatabaseQuery()) { Product product = querry.GetProduct(productId); return View(product); } }
public ActionResult ChangeProduct(ulong productId) { try { using (DatabaseQuery query = new DatabaseQuery()) { ProductViewModel pvm = FillProductViewModel(); pvm.Product = query.GetProduct(productId); pvm.SelectedCategoryId = pvm.Product.Category.Id; return View(pvm); } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het ophalen van het product: " + e; return View(); } }