Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("StoreID,ProductID,StockLevel")] StoreInventory storeInventory)
        {
            if (id != storeInventory.StoreID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(storeInventory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StoreInventoryExists(storeInventory.StoreID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", storeInventory.ProductID);
            ViewData["StoreID"]   = new SelectList(_context.Stores, "StoreID", "StoreID", storeInventory.StoreID);
            return(View(storeInventory));
        }
Esempio n. 2
0
        public async Task <IActionResult> Pay(CreditCardForm creditCardForm)
        {
            // Validate card type.
            CardType expectedCardType = CardTypeInfo.GetCardType(creditCardForm.CreditCardNumber);

            if (expectedCardType == CardType.Unknown || expectedCardType != creditCardForm.CreditCardType)
            {
                ModelState.AddModelError("CreditCardType", "The Credit Card Type field does not match against the credit card number.");
            }

            if (!ModelState.IsValid)
            {
                return(View(creditCardForm));
            }

            var purchaseList = await customer.ProcessCart();

            Order order = new Order();

            order.CustomerID = customer.ID;
            order.Date       = DateTime.Now;
            order.TotalPrice = decimal.Round(purchaseList.Sum(p => p.SubTotal), 2);
            _context.Update(order);
            await _context.SaveChangesAsync();

            ViewData["orderID"]    = order.OrderID;
            ViewData["TotalPrice"] = order.TotalPrice;
            ViewData["Date"]       = order.Date;

            return(View("Confirmation", purchaseList));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ProductID,StockLevel")] OwnerInventory ownerInventory)
        {
            _context.Update(ownerInventory);
            await _context.SaveChangesAsync();

            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", ownerInventory.ProductID);
            return(RedirectToAction(nameof(Index)));
        }