Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductID,Name,Quantity,UnitPrice")] Product product)
        {
            if (id != product.ProductID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Esempio n. 2
0
        //public async Task<IActionResult> Edit(int id, [Bind("CartID,ShopperID,TimeSlot,Subtotal,Tax,TotalCost,CheckedOut")] Cart cart)
        //{
        //    if (id != cart.CartID)
        //    {
        //        return NotFound();
        //    }

        //    if (ModelState.IsValid)
        //    {
        //        try
        //        {
        //            _context.Update(cart);
        //            await _context.SaveChangesAsync();
        //        }
        //        catch (DbUpdateConcurrencyException)
        //        {
        //            if (!CartExists(cart.CartID))
        //            {
        //                return NotFound();
        //            }
        //            else
        //            {
        //                throw;
        //            }
        //        }
        //        return RedirectToAction(nameof(Index));
        //    }
        //    ViewData["ShopperID"] = new SelectList(_context.Shopper, "ShopperID", "Email", cart.ShopperID);
        //    return View(cart);
        //}

        // The Edit action is used to check out the shopper cart.
        public async Task <IActionResult> Edit(int id, [Bind("CartID,ShopperID")] Cart cart)
        {
            if (id != cart.CartID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                // 4) Include the required code to checkout the cart.



                try
                {
                    _context.Update(cart);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CartExists(cart.CartID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), "Carts", new { id = cart.CartID }));
            }
            ViewData["ShopperID"] = new SelectList(_context.Shopper, "ShopperID", "FirstName", cart.ShopperID);
            return(View(cart));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("ShopperID,LastName,FirstName,Email")] Shopper shopper)
        {
            if (id != shopper.ShopperID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shopper);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShopperExists(shopper.ShopperID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shopper));
        }