コード例 #1
0
        public IActionResult Create(AchIngredient newItem)
        {
            var newId = _context.AchIngredient.OrderByDescending(i => i.IdIngredient).FirstOrDefault().IdIngredient + 1;

            newItem.IdIngredient = newId;

            _context.AchIngredient.Add(newItem);
            _context.SaveChanges();
            return(StatusCode(201, newItem));
        }
コード例 #2
0
        public IActionResult Update(int item_id, AchIngredient updated_item)
        {
            if (_context.AchIngredient.Count(e => e.IdIngredient == item_id) == 0)
            {
                return(NotFound());
            }

            _context.AchIngredient.Attach(updated_item);
            _context.Entry(updated_item).State = EntityState.Modified;
            _context.SaveChanges();
            return(Ok(updated_item));
        }