コード例 #1
0
        public ActionResult Edit(BooksViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                var bookModelId = _unitOfWork.Repo.GetBooks().FirstOrDefault(b => b.BookId == model.BookId).BookId;
                var authorname  = _unitOfWork.Repo.GetAuthors().FirstOrDefault(b => b.AuthorId == model.AuthorId).FullName;
                model.PreparForEdit(bookModelId);

                model.AuthorName = authorname;

                return(View(model));
            }
            try
            {
                var m = Mapper.Map <BooksViewModel, Book>(model);
                _unitOfWork.Repo.EditBook(m);
                _unitOfWork.Complete();

                return(RedirectToAction("Details", new
                {
                    id = m.BookId
                }));
            }
            catch
            {
                return(View("Error"));
            }
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            var model = new BooksViewModel();
            var m     = _unitOfWork.Repo.GetBooks().FirstOrDefault(b => b.BookId == id);

            model = Mapper.Map <Book, BooksViewModel>(m);
            model.PreparForEdit(id);

            return(View(model));
        }