public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,NewOrderId")] ProductsNewOrder productsNewOrder)
        {
            if (id != productsNewOrder.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productsNewOrder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsNewOrderExists(productsNewOrder.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["NewOrderId"] = new SelectList(_context.NewOrder, "Id", "CW", productsNewOrder.NewOrderId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Category", productsNewOrder.ProductId);
            return(View(productsNewOrder));
        }
        public async Task <IActionResult> Create([Bind("Id,ProductId,NewOrderId")] ProductsNewOrder productsNewOrder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productsNewOrder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["NewOrderId"] = new SelectList(_context.NewOrder, "Id", "CW", productsNewOrder.NewOrderId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Category", productsNewOrder.ProductId);
            return(View(productsNewOrder));
        }
 public async Task<IActionResult> Create([Bind("Id,UserId,CreditNum,ExpireMonth,ExpireYear,OwnName,IdNum,CW")] NewOrder newOrder)
 {
     if (ModelState.IsValid)
     {
         _context.Add(newOrder);
         await _context.SaveChangesAsync();
         string cart = HttpContext.Session.GetString("cart");
         string[] productIdscart = cart.Split(",", StringSplitOptions.RemoveEmptyEntries);
         foreach (var id in productIdscart)
         {
             ProductsNewOrder po = new ProductsNewOrder();
             po.ProductId = int.Parse(id);
             po.NewOrderId = newOrder.Id;
       
             _context.Add(po);
             
         }
         await _context.SaveChangesAsync();
         HttpContext.Session.SetString("Cart", "");
         return RedirectToAction(nameof(Index));
     }
     return View(newOrder);
 }