public async Task <IActionResult> PutBook(int id, Book book) { var bookToUpdate = await _context.Books.FindAsync(id); if (bookToUpdate == null) { return(BadRequest()); } book.BookID = bookToUpdate.BookID; _context.Entry(bookToUpdate).CurrentValues.SetValues(book); _context.Books.Update(bookToUpdate); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutReading([FromRoute] int id, [FromBody] Reading reading) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != reading.Id) { return(BadRequest()); } var userId = User.Claims.FirstOrDefault(c => c.Type == "uid")?.Value; if (_context.Reading.FirstOrDefault(c => c.UserId == userId && c.Id == id) == null) { return(NotFound()); } _context.Entry(reading).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> PutAuthor(int id, Author author) { var authorToUpdate = await _context.Authors.FindAsync(id); author.AuthorID = authorToUpdate.AuthorID; _context.Entry(authorToUpdate).CurrentValues.SetValues(author); _context.Authors.Update(authorToUpdate); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutRating(int id, Rating rating) { var ratingToUpdate = await _context.Ratings.FindAsync(id); if (ratingToUpdate == null) { return(BadRequest()); } rating.RatingID = ratingToUpdate.RatingID; _context.Entry(ratingToUpdate).CurrentValues.SetValues(rating); _context.Ratings.Update(ratingToUpdate); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RatingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }