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()); }
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)); }
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)); }