public IActionResult AddOrder(Order NewOrder, int quantity, int ProductId)
        {
            Product Orderupdate = _context.Products.SingleOrDefault(Product => Product.ProductId == ProductId);

            if (quantity > Orderupdate.quantity)
            {
                TempData["invalidorder"] = "Cannot Order more than";
                return(RedirectToAction("Orders"));
            }
            Orderupdate.quantity -= quantity;
            _context.Add(NewOrder);
            _context.SaveChanges();
            return(RedirectToAction("Orders"));
        }
        public IActionResult NewProduct(Product model)
        {
            if (ModelState.IsValid)
            {
                Product product = new Product {
                    Name              = model.Name,
                    Description       = model.Description,
                    ImageUrl          = "/images/" + model.ImageUrl + ".jpg",
                    QuantityAvailable = model.QuantityAvailable,
                    created_at        = DateTime.Now,
                    updated_at        = DateTime.Now
                };

                _context.Add(product);
                _context.SaveChanges();
                return(RedirectToAction("Products"));
            }
            return(View("Products"));
        }
        public IActionResult Register(Customer model)
        {
            if (ModelState.IsValid)
            {
                Customer customer = new Customer {
                    FirstName  = model.FirstName,
                    LastName   = model.LastName,
                    Email      = model.Email,
                    created_at = DateTime.Now,
                    updated_at = DateTime.Now
                };

                _context.Add(customer);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View("Index"));
        }
        public IActionResult NewOrder(Order model)
        {
            if (ModelState.IsValid)
            {
                Order order = new Order {
                    CustomerId = model.CustomerId,
                    ProductId  = model.ProductId,
                    Quantity   = model.Quantity,
                    created_at = DateTime.Now,
                    updated_at = DateTime.Now
                };
                _context.Add(order);

                Product RetrievedProduct = _context.Products.SingleOrDefault(p => p.ProductId == model.ProductId);
                RetrievedProduct.QuantityAvailable -= model.Quantity;

                _context.SaveChanges();
                return(RedirectToAction("Orders"));
            }
            return(View("Orders"));
        }