public IActionResult Buy(int id) { Productwaarde productModel = new Productwaarde(); if (SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart") == null) { List <Item> cart = new List <Item>(); cart.Add(new Item { Product = _context.Productwaarde.Find(id), Quantity = 1 }); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); int index = isExist(id); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new Item { Product = _context.Productwaarde.Find(id), Quantity = 1 }); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create3(Productwaarde productwaarde) { if (ModelState.IsValid) { _context.Productwaarde.Add(productwaarde); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }