public async Task <ActionResult <CartIngredient> > PostCartIngredient(CartIngredient cartIngredient) { _context.CartIngredient.Add(cartIngredient); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCartIngredient", new { id = cartIngredient.Id }, cartIngredient)); }
public async Task <IActionResult> PutCartIngredient(int id, CartIngredient cartIngredient) { if (id != cartIngredient.Id) { return(BadRequest()); } _context.Entry(cartIngredient).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CartIngredientExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public int CreateCart(Dictionary <int, int> orderList, double total) { Cart cart = new Cart(); cart.Total = total; cart.IndActive = true; cart.CartIngredients = new List <CartIngredient>(); foreach (var keyValuePairLoop in orderList) { CartIngredient cartIngredientLoop = new CartIngredient(); cartIngredientLoop.IngredientId = keyValuePairLoop.Key; cartIngredientLoop.Quantity = keyValuePairLoop.Value; cart.CartIngredients.Add(cartIngredientLoop); } _context.Carts.Add(cart); _context.SaveChanges(); return(cart.CartId); }