public IHttpActionResult PutAuthor(int id, Author author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != author.AuthorID) { 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 IHttpActionResult PutBook(Guid id, Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.GUID) { return(BadRequest()); } book.UpdatedAt = DateTime.Now; db.Entry(book).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(StatusCode(HttpStatusCode.NotFound)); } else { throw; } } return(Ok(0)); }
public IHttpActionResult PutTitle(string id, Title title) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != title.ISBN) { return(BadRequest()); } db.Entry(title).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TitleExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "AuthorID,FirstName,LastName")] 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,Title,Author,Publisher,PageNumber")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "ISBN,Title1,EditionNumber,Copyright")] Title title) { if (ModelState.IsValid) { db.Entry(title).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(title)); }
//метод редагування інформації книги. //[FromBody] - інформація про книгу передається в тілі запиту public IHttpActionResult Patch(int Id, [FromBody] Book book) { // спробувати оновити інформацію про книгу try { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(Ok(book)); } // якщо трапиться помилка - повернути Internal Server Error catch (Exception error) { return(InternalServerError(error)); } }
public void Remove(int id) { using (var context = new BooksEntities()) { var bookToRemove = context.Books.SingleOrDefault(b => b.ID == id); if (bookToRemove != null) { context.Entry(bookToRemove).State = EntityState.Deleted; context.SaveChanges(); } else { throw new DBConcurrencyException(); } } }
public void EditBookById(Book book) { if (!ModelState.IsValid) { return; } var fbook = db.Books.FirstOrDefault(m => m.BookId == book.BookId); if (fbook == null) { throw new ArgumentNullException(nameof(fbook)); } db.Entry(fbook).CurrentValues.SetValues(book); db.SaveChangesAsync(); Response.Write("Succesfully updated data...."); }
public void UpdateUser(Users user) { context.Entry(user).State = EntityState.Modified; }
public void UpdateBook(Book book) { context.Entry(book).State = EntityState.Modified; }
public IHttpActionResult Delete(int id) { bool selll = false; if (id <= 0) { return(BadRequest("Not a valid Book id")); } var selby = (from i in db.Seller_Buyer_Book select i.Book_Id).ToList(); foreach (var item in selby) { if (item == id) { selll = true; } } if (selll) { return(BadRequest("Not a valid Book id")); } else { using (var ctx = new BooksEntities()) { var bookrequest = ctx.Requests .Where(s => s.Book_Id == id) .FirstOrDefault(); if (bookrequest != null) { ctx.Entry(bookrequest).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } var bookapproved = ctx.Seller_Approved_book .Where(s => s.Book_Id == id) .FirstOrDefault(); if (bookapproved != null) { ctx.Entry(bookapproved).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } var imglist = (from i in db.Images where i.Book_Id == id select i.Id).ToList(); foreach (var item in imglist) { var img = db.Images.Where(e => e.Id == item).First(); if (img != null) { db.Images.Remove(img); db.SaveChanges(); } } var book = ctx.Books .Where(s => s.Id == id) .FirstOrDefault(); ctx.Entry(book).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } } return(Ok()); }
public void UpdateReview(Review review) { context.Entry(review).State = EntityState.Modified; }