public async Task <IActionResult> PutProduct(int id, Product product)
        {
            //if (id != product.Id)
            //{
            //    return BadRequest();
            //}

            product.Id = id;

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutShoppingListProduct(int id, ShoppingListProduct shoppingListProduct)
        {
            if (id != shoppingListProduct.ShoppingListId)
            {
                return(BadRequest());
            }

            _context.Entry(shoppingListProduct).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShoppingListProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Пример #4
0
        async Task <bool> IItemService.Remove(int id)
        {
            var item = await _context.Items.SingleOrDefaultAsync(x => x.Id == id);

            if (item == null)
            {
                return(false);
            }

            _context.Items.Remove(item);
            await _context.SaveChangesAsync();

            return(true);
        }
Пример #5
0
        public async Task <IActionResult> Post([FromBody] Entities.ShoppingList value)
        {
            if (value == null)
            {
                return(BadRequest());
            }

            await db.ShoppingLists.AddAsync(value);

            await db.SaveChangesAsync();

            await notifications.NotifyRefreshList();

            return(CreatedAtRoute("GetShoppingList", new { id = value.Id }, value));
        }