Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("OrderAndProductId,OrderId,ProductId")] OrderAndProduct orderAndProduct)
        {
            if (id != orderAndProduct.OrderAndProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(orderAndProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderAndProductExists(orderAndProduct.OrderAndProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Order, "Id", "Id", orderAndProduct.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Product, "Id", "Id", orderAndProduct.ProductId);
            return(View(orderAndProduct));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("OrderAndProductId,OrderId,ProductId")] OrderAndProduct orderAndProduct)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderAndProduct);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Order, "Id", "Id", orderAndProduct.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Product, "Id", "Id", orderAndProduct.ProductId);
            return(View(orderAndProduct));
        }
        public async Task <IActionResult> CreateAuto()
        {
            Global.ord = new Order();
            if (ModelState.IsValid)
            {
                _context.Add(Global.ord);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Id");
            if (ModelState.IsValid)
            {
                int size = Global.CurrentCart.Products.Count;
                for (int i = 0; i < size; i++)
                {
                    OrdAndPro = new OrderAndProduct();
                    _context.Add(OrdAndPro);
                    await _context.SaveChangesAsync();

                    //return RedirectToAction(nameof(Index));
                    var result = (from p in _context.Product
                                  where p.Id == Global.CurrentCart.Products.FirstOrDefault().Id
                                  select p).FirstOrDefault();
                    result.Unit -= Global.CurrentCart.Products.FirstOrDefault().Unit;
                    _context.SaveChanges();
                    if (!(i == size - 1))
                    {
                        Global.CurrentCart.Products.RemoveAt(i);
                    }
                }
                Global.CurrentCart = new Cart();
            }

            return(RedirectToAction("ProductHome", "Products"));
        }