Пример #1
0
        public IActionResult Create(int publisherId)
        {
            BookCreateViewModel model = new BookCreateViewModel();

            model.LoadModelData(_unitOfWork, publisherId);
            return(View(model));
        }
Пример #2
0
 public IActionResult Create(BookCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         _unitOfWork.BookRepository.SaveNewBook(model.Book);
         try
         {
             _unitOfWork.Save();
             return(RedirectToAction("Details", "Home", new { publisherId = model.Book.Publisher_Id }));
         }
         catch (ValidationException ValidationException)
         {
             ModelState.AddModelError($"{nameof(Book)}.{nameof(Book.Title)}", ValidationException.ValidationResult.ErrorMessage);
         }
     }
     model.LoadModelData(_unitOfWork, model.Book.Publisher_Id);
     return(View(model));
 }