コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public void Upsert(Book book)
 {
     Books[book.Id] = book;
 }