public bool UpdateBook(BookModel book) { var index = books.FindIndex(b => b.Id == book.Id); if (index == -1) return false; books.RemoveAt(index); books.Insert(index, book); return true; }
public JsonResult Add() { var book = new BookModel { Title = "New book", Author = "Unknown", Year = DateTime.Now.Year }; Library.AddBook(book); return Json(Library.GetBooks(), JsonRequestBehavior.AllowGet); }
public void AddBook(BookModel book) { book.Id = nextId++; books.Add(book); }
public ActionResult Edit(BookModel book) { Library.UpdateBook(book); return RedirectToAction("Index"); }