public async Task <IActionResult> Edit(int id, [Bind("Id,IdCart,IdProduct,Number")] InCart inCart) { if (id != inCart.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(inCart); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InCartExists(inCart.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(inCart)); }
public async Task <IActionResult> Create([Bind("Id,IdCart,IdProduct,Number")] InCart inCart) { if (ModelState.IsValid) { _context.Add(inCart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(inCart)); }
public IActionResult AddToCart(int idproduct) { // temporary InCart having information about buying product InCart MyProduct = new InCart(); MyProduct.IdProduct = idproduct; MyProduct.Number = 1; // is there the product in the cart InCart tmp = ProductsInCart.Find(p => p.IdProduct == idproduct); // if not add product with number = 1 if (tmp == null) { ProductsInCart.Add(MyProduct); } return(RedirectToAction("Index")); }