public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.CategoryId) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> SaveChanges(int id, Book book) { if (id != book.Id) { return(BadRequest()); } // _db.Books.Find(id).CategoryId = book.CategoryId; _db.Entry(book).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }