public async Task <IHttpActionResult> PutBook(int id, Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.Id) { return(BadRequest()); } db.Entry(book).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void UpdateAuthor(Author author) { Author a = context.Authors.Find(author.Id); if (a is not null) { a.Name = author.Name; context.Entry(a).State = EntityState.Modified; context.SaveChanges(); } }
public IHttpActionResult PutAuthor(int id, Author author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != author.Id) { return(BadRequest()); } db.Entry(author).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "GenreId,GenreName")] Genre genre) { if (ModelState.IsValid) { //check if the same genre exists var genreExists = db.Genres.Count(g => g.GenreName == genre.GenreName); if (genreExists == 0) { db.Entry(genre).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(genre)); }