Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Shoppinglist_id,Product_id,Amount")] Shoppinglist_Product shoppinglist_Product)
        {
            if (id != shoppinglist_Product.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shoppinglist_Product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Shoppinglist_ProductExists(shoppinglist_Product.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Product_id"]      = new SelectList(_context.Products, "Id", "Description", shoppinglist_Product.Product_id);
            ViewData["Shoppinglist_id"] = new SelectList(_context.ShoppingLists, "id", "Customer_id", shoppinglist_Product.Shoppinglist_id);
            return(View(shoppinglist_Product));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("id,Shoppinglist_id,Product_id,Amount")] Shoppinglist_Product shoppinglist_Product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppinglist_Product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Product_id"]      = new SelectList(_context.Products, "Id", "Description", shoppinglist_Product.Product_id);
            ViewData["Shoppinglist_id"] = new SelectList(_context.ShoppingLists, "id", "Customer_id", shoppinglist_Product.Shoppinglist_id);
            return(Redirect("/ShoppingLists"));
        }