public async Task <IActionResult> Edit(int id, [Bind("Id,count,price,cartId,cocktailId")] CartItem cartItem) { if (id != cartItem.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cartItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CartItemExists(cartItem.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["cartId"] = new SelectList(_context.Cart, "Id", "Id", cartItem.cartId); ViewData["cocktailId"] = new SelectList(_context.Cocktail, "Id", "Id", cartItem.cocktailId); return(View(cartItem)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,title,units,color,description")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,unit,quantity,cocktailId,productId")] CocktailProduct cocktailProduct) { if (id != cocktailProduct.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cocktailProduct); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CocktailProductExists(cocktailProduct.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["cocktailId"] = new SelectList(_context.Cocktail, "Id", "Id", cocktailProduct.cocktailId); ViewData["productId"] = new SelectList(_context.Product, "Id", "Id", cocktailProduct.productId); return(View(cocktailProduct)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,full_price,userId")] Cart cart) { if (id != cart.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cart); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CartExists(cart.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["userId"] = new SelectList(_context.User, "Id", "Id", cart.userId); return(View(cart)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,title,price,color,proof,category")] Cocktail cocktail, string[] selectedProducts) { if (id != cocktail.Id) { return(NotFound()); } // validate if (ModelState.IsValid) { try { var cocktailOld = await _context.Cocktail .Include(o => o.cocktailProducts) .ThenInclude(o => o.product) .FirstOrDefaultAsync(o => o.Id == id); cocktailOld.title = cocktail.title; cocktailOld.price = cocktail.price; cocktailOld.proof = cocktail.proof; cocktailOld.color = cocktail.color; cocktailOld.category = cocktail.category; UpdateCocktailProducts(selectedProducts, cocktailOld); _context.Update(cocktailOld); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CocktailExists(cocktail.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cocktail)); }