public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,PName,PDescribe,PPrice,PNum")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminProduct)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([FromBody] PaymentInfo paymentInfo)
        {
            if (_context.PaymentInfo.ToArray().Length == 0)
            {
                paymentInfo.Id = 1;
            }
            else
            {
                paymentInfo.Id = _context.PaymentInfo.ToArray()[_context.PaymentInfo.ToArray().Length - 1].Id + 1;
            }
            _context.Add(paymentInfo);
            await _context.SaveChangesAsync();

            return(new StatusCodeResult(201));
        }
Ejemplo n.º 4
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind("ID,ProductName,ReleaseDate,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                if (_context.Product.ToArray().Length == 0)
                {
                    product.ID = 1;
                }
                else
                {
                    product.ID = _context.Product.ToArray()[_context.Product.ToArray().Length - 1].ID + 1;
                }
                _context.Product.Add(product);
                Console.WriteLine("product is " + product.ID + product.ProductName);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Ejemplo n.º 5
0
        //[ValidateAntiForgeryToken]
        public async Task <StatusCodeResult> Create([FromBody] ShoppingCartItem shoppingCartItem)
        {
            if (shoppingCartItem == null)
            {
                return(new Microsoft.AspNetCore.Mvc.BadRequestResult());
            }
            else
            {
                if (_context.ShoppingCartItem.ToArray().Length == 0)
                {
                    shoppingCartItem.ID = 1;
                }
                else
                {
                    shoppingCartItem.ID = _context.ShoppingCartItem.ToArray()[_context.ShoppingCartItem.ToArray().Length - 1].ID + 1;
                }
                _context.ShoppingCartItem.Add(shoppingCartItem);
                await _context.SaveChangesAsync();

                return(new StatusCodeResult(201));
            }
        }
Ejemplo n.º 6
0
        public async Task <StatusCodeResult> Create([FromBody] User user)
        {
            if (user == null)
            {
                return(new Microsoft.AspNetCore.Mvc.BadRequestResult());
            }
            else
            {
                if (_context.User.ToArray().Length == 0)
                {
                    user.ID = 1;
                }
                else
                {
                    user.ID = _context.User.ToArray()[_context.User.ToArray().Length - 1].ID + 1;
                }
                _context.User.Add(user);
                await _context.SaveChangesAsync();

                return(new StatusCodeResult(201));
            }
        }