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 (Exception ex) { if (!BookExists(id)) { return(NotFound()); } else { throw ex; } } return(this.StatusCode(HttpStatusCode.NoContent)); }
public Book Create(Book book) { db.Entry <Book>(book).State = EntityState.Added; if (db.SaveChanges() > 0) { return(book); } return(default(Book)); }
public ActionResult Edit([Bind(Include = "AuthorId,FirstName,LastName,MiddleName,InStock")] Author author) { if (ModelState.IsValid) { db.Entry(author).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(author)); }
public ActionResult Edit([Bind(Include = "BookId,BookTitle,AuthorId,Description,Category,Price,BookCover,InStock")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = book.BookId })); } ViewBag.AuthorId = new SelectList(db.Authors, "AuthorId", "LastName", book.Author); return(View(book)); }
private void ExplicitLoading(BookDbContext context, int id) { var book = context.Books.Single(x => x.BookId == id); context.Entry(book).Collection(c => c.AuthorsLink).Load(); foreach (var authorLink in book.AuthorsLink) { context.Entry(authorLink) .Reference(r => r.Author).Load(); } context.Entry(book).Collection(c => c.Reviews).Load(); context.Entry(book).Collection(c => c.Tags).Load(); }
public async Task <IActionResult> PutAuthorBiography(int id, AuthorBiography authorBiography) { if (id != authorBiography.AuthorBiographyId) { return(BadRequest()); } _context.Entry(authorBiography).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorBiographyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <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 { await _db.SaveChangesAsync(); } catch (Exception ex) { if (!AuthorExists(id)) { return(NotFound()); } else { throw ex; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutBook([FromRoute] int id, [FromBody] Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.Id) { return(BadRequest()); } _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Delete(Book book) { if (_dbContext.Entry(book).State == EntityState.Detached) { _dbSet.Attach(book); } _dbSet.Remove(book); }
public ActionResult Edit([Bind(Include = "ID,Title,Author,Type,Publisher,PublishTime,Price")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "BookId,BookName,Publisher_,Avalability")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "BookId,BookName,Author,Edition,Price,Quantity,AddedDate,ModifiedDate,Availablity")] BookInfo bookinfo) { if (ModelState.IsValid) { db.Entry(bookinfo).State = EntityState.Modified; //bookinfo.AddedDate = DateTime.Now; bookinfo.ModifiedDate = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookinfo)); }
public IActionResult Edit(Review review) { if (ModelState.IsValid) { // context.Reviews.Add(review); context.Entry(review).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index", new { id = review.BookId })); } return(View(review)); }
public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName,UserName,Email,Password,Role,CreatedDateTime,ConfirmPassword")] User user) { if (ModelState.IsValid) { //Для запобігання крос-скриптовим атакам, встановлюю роль тут, //незалежно від того, що летить на сервер. user.Role = "U"; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { email = user.Email })); } return(View(user)); }
// PUT api/book/5 public HttpResponseMessage Put(Book model) { if (ModelState.IsValid) { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, model); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public async Task <IActionResult> PutBook(int id, BookListViewModel bookModel) { Book book = bookModel.ConvertToBookFromModel(); if (id != book.BookId) { return(BadRequest()); } var stateChanger = bookDbContext.Entry <Book>(book); stateChanger.State = EntityState.Modified; await bookDbContext.SaveChangesAsync(); return(NoContent()); }
public ActionResult Delete(int id, FormCollection collection) { try { var deletableBook = dbContext.Books.First(x => x.Id == id); dbContext.Entry(deletableBook).Collection(x => x.Hits).Load(); dbContext.Books.Remove(deletableBook); dbContext.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <RemoveBookCommandResponse> RemoveBook(RemoveBookCommand request) { var book = await _bookDbContext.Books.FirstOrDefaultAsync(x => x.Id == request.Id); if (book is not null) { _bookDbContext.Entry(book).State = EntityState.Deleted; await _bookDbContext.SaveChangesAsync(); return(new RemoveBookCommandResponse { Deleted = true }); } return(new RemoveBookCommandResponse { Deleted = false }); }
public int UpdateBook(int id, Book Book) { _context.Entry(Book).State = EntityState.Modified; try { _context.Books.Update(Book); _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return((int)ReturnCode.NOT_FOUND); } else { throw; } } return((int)ReturnCode.NO_CONTENT); }