public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,CardNumber")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customers));
        }
        public async Task <IActionResult> Create([Bind("Id,Address,City,State")] Locations locations)
        {
            if (ModelState.IsValid)
            {
                _context.Add(locations);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(locations));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Category,Price")] Products products)
        {
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(products));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,LocationId,CustomerId,OrderDate,Total")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "FirstName", orders.CustomerId);
            ViewData["LocationId"] = new SelectList(_context.Locations, "Id", "Address", orders.LocationId);
            return(View(orders));
        }
        public async Task <IActionResult> Create([Bind("Id,LocationId,ProductId,Stock")] Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(inventory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocationId"] = new SelectList(_context.Locations, "Id", "Address", inventory.LocationId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Name", inventory.ProductId);
            return(View(inventory));
        }
        public async Task <IActionResult> PlaceOrder()
        {
            if (ModelState.IsValid)
            {
                if (ShoppingCart == null)
                {
                    ViewData["Message"] = "I'm sorry, but you don't have a shopping cart.";
                }
                else if (ShoppingCart.OrderItems.Count == 0)
                {
                    ViewData["Message"] = "I'm sorry, but you haven't added anything to your cart.";
                }
                else
                {
                    foreach (var item in ShoppingCart.OrderItems)
                    {
                        var inventory = _context.Inventory.First(i => i.LocationId == ShoppingCart.LocationId && i.ProductId == item.ProductId);
                        inventory.Stock -= item.Quantity;
                    }
                    _context.Add(ShoppingCart);
                    await _context.SaveChangesAsync();

                    ViewData["Message"] = "Your order has been placed!";
                    ShoppingCart        = null;
                }
            }
            return(View());
        }