public async Task <IActionResult> PutItems(long id, Items items)
        {
            if (id != items.Id)
            {
                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 IHttpActionResult PutItem(int id, Item item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(item).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public async Task <bool> UpdateItemAsync(Item item)
        {
            int count = 0;

            using (var context = new ItemDbContext())
            {
                context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                count = await context.SaveChangesAsync();
            }
            return(await Task.FromResult(count == 1));
        }