コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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"));
        }