public async Task <IActionResult> PutShoppingListProduct(int id, ShoppingListProduct shoppingListProduct) { if (id != shoppingListProduct.ShoppingListProductId) { return(BadRequest()); } _context.Entry(shoppingListProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingListProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <ShoppingListProduct> > PostShoppingListProduct(ShoppingListProduct shoppingListProduct) { _context.ShoppingListProduct.Add(shoppingListProduct); await _context.SaveChangesAsync(); var newShoppingListProduct = await _context.ShoppingListProduct.Include(slp => slp.Product) .Where(slp => slp.ShoppingListProductId == shoppingListProduct.ShoppingListProductId) .FirstOrDefaultAsync(); return(newShoppingListProduct); //return CreatedAtAction("GetShoppingListProduct", new { id = shoppingListProduct.ShoppingListProductId }, shoppingListProduct); }
public async Task <ActionResult <ShoppingListProduct> > PostShoppingListProduct(ShoppingListProduct shoppingListProduct) { _context.ShoppingListProduct.Add(shoppingListProduct); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ShoppingListProductExists(shoppingListProduct.ShoppingListId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetShoppingListProduct", new { id = shoppingListProduct.ShoppingListId }, shoppingListProduct)); }