public ActionResult Create(Book book) { if (book != null) { book.Id = ++BookProvider.Counter; BookProvider.Instance.AllBooks.Add(book); } return View("BookList", BookProvider.Instance.AllBooks); }
static BookProvider() { Instance = new BookProvider(); Instance.AllBooks = new List<Book>(); for (int i = 1; i <= 10 ; i++) { Counter++; Book book = new Book() { Id = i, Name = String.Format("Book #{0}", i), Price = i }; Instance.AllBooks.Add(book); } }
public ActionResult Edit(Book book) { if (book != null) { Book editingBook = BookProvider.Instance.AllBooks.SingleOrDefault(b => b.Id == book.Id); if (editingBook != null) { editingBook.Name = book.Name; editingBook.Price = book.Price; } } return View("BookList", BookProvider.Instance.AllBooks); }