private void UpdateBook(Book book, BookViewModel viewModel) { book.Id = viewModel.Id; book.Author = viewModel.Author; book.Name = viewModel.Name; book.Published = viewModel.DatePublished.GetValueOrDefault(); book.Rating = viewModel.Rating; }
private BookViewModel ViewModelFromBook(Book book) { var viewModel = new BookViewModel { Id = book.Id, Name = book.Name, Author = book.Author, DatePublished = book.Published, Rating = book.Rating }; return viewModel; }
public ActionResult Create(BookViewModel viewModel) { if (ModelState.IsValid) { viewModel.Id = Guid.NewGuid(); var book = new Book(); UpdateBook(book, viewModel); bookRepository.Upsert(book); return RedirectToAction("Index"); } return View(viewModel); }
public void Upsert(Book book) { Books[book.Id] = book; }