Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("PairId,ProductQuantity,ProductId,OrderId")] ProductOrderPair productOrderPair)
        {
            if (id != productOrderPair.PairId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productOrderPair);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductOrderPairExists(productOrderPair.PairId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Orders, "OrderId", "OrderId", productOrderPair.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", productOrderPair.ProductId);
            return(View(productOrderPair));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("PairId,ProductQuantity,ProductId,OrderId")] ProductOrderPair productOrderPair)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productOrderPair);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Orders, "OrderId", "OrderId", productOrderPair.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", productOrderPair.ProductId);
            return(View(productOrderPair));
        }