public ActionResult CreateEdit(Book book) { if (book.Id == 0) { book.ModifiedDate = System.DateTime.Now; book.AddedDate = System.DateTime.Now; book.IP = Request.UserHostAddress; bookRepository.Insert(book); } else { var editbook = bookRepository.GetById(book.Id); editbook.Title = book.Title; editbook.Author = book.Author; editbook.ISBN = book.ISBN; editbook.Published = book.Published; editbook.ModifiedDate = System.DateTime.Now; editbook.IP = Request.UserHostAddress; bookRepository.Update(editbook); } if (book.Id > 0) { return RedirectToAction("Index"); } return View(book); }
// GET: Book/Create public ActionResult CreateEdit(int? id) { Book book = new Book(); if (id.HasValue) { book = bookRepository.GetById(id); } return View(book); }