コード例 #1
0
        public async Task <IActionResult> PutItems([FromRoute] int id, [FromBody] Items items)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != items.ItemId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutCategories([FromRoute] int id, [FromBody] Categories categories)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categories.CategoryId)
            {
                return(BadRequest());
            }

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

            foreach (var itemcategory in categories.ItemCategories)
            {
                _context.ItemCategories.Add(itemcategory);
            }

            var currentItemCategories = _context.ItemCategories.Where(ic => ic.CategoryId == categories.CategoryId);

            _context.ItemCategories.RemoveRange(currentItemCategories);

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

            return(NoContent());
        }