static BookProviders() { Instance = new BookProviders(); Instance.AllBooks = new List<Books>(); for (int i = 1; i <= 50; i++) { Books book = new Books() { Id = i, Name = String.Format("Book #{0}", i), Price = i }; Instance.AllBooks.Add(book); } Counter = 0; }
public ActionResult Create(Books book) { if (book.Name == null || book.Price == null) { return View("CreateError"); } else if (book != null && this.ModelState.IsValid) { book.Id = ++BookProviders.Counter + 50; BookProviders.Instance.AllBooks.Add(book); return RedirectToAction("Show", new { pageNumber = 1 }); } else { return RedirectToAction("Show", new { pageNumber = 1 }); } }
public ActionResult Edit(Books book) { if (book.Name != null && book.Price != null && this.ModelState.IsValid) { Books updatedBook = BookProviders.Instance.AllBooks.SingleOrDefault(b => b.Id == book.Id); if (updatedBook != null) { updatedBook.Name = book.Name; updatedBook.Price = book.Price; } } else { return View("EditError"); } return RedirectToAction("Show", new { pageNumber = 1 }); }