public ActionResult Index(BooksModel book) { if(!ModelState.IsValid) { return View(book); } TempData["Books"] = book; return RedirectToRoute(new { @controller = "Components", @action = "Index", @id = book.BookId }); //return RedirectToAction("NextPage", "Home"); }
public IHttpActionResult PutBook(long id, BooksModel booksModel) { if (id != booksModel.BookId) return BadRequest(); if (!ModelState.IsValid) return BadRequest(ModelState); var book = db.Books.Find(id); if (book == null) return StatusCode(HttpStatusCode.NotFound); // MAP using SERVICE book.BookId = booksModel.BookId; book.Description = booksModel.Description; book.Title = booksModel.Title; book.PublishDate = booksModel.PublishDate; book.Author.FirstName = booksModel.AuthorFirstName; book.Author.LastName = booksModel.AuthorLastName; try { // UPDATE using SERVICE db.Entry(book).State = EntityState.Modified; db.SaveChanges(); } catch (Exception) { return StatusCode(HttpStatusCode.InternalServerError); } return StatusCode(HttpStatusCode.Accepted); }