示例#1
0
        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());
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }