public ActionResult Create(BookViewModel book, string prevPageUrl) { if (ModelState.IsValid) { _booksRepository.AddElem(BookConverter.ConvertViewModelToModel(book)); TempData["message"] = $"Книга \"{book.Title}\" успешно добавлена"; return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).Replace("Controller", ""))); } else { return(View(new ActionBooksPagesViewModel { Book = book, Genres = new SelectList(_genresRepository.GetAllGenres(), nameof(Genre.Id), nameof(Genre.Title)), PrevPageUrl = prevPageUrl })); } }
public ActionResult Edit(BookViewModel book, string prevPageUrl) { if (book.Id <= 0) { throw new ArgumentException("Book ID is empty or <= 0"); } if (ModelState.IsValid) { _booksRepository.EditElem(BookConverter.ConvertViewModelToModel(book)); TempData["message"] = $"Книга \"{book.Title}\" успешно изменена"; return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).Replace("Controller", ""))); } else { return(View(new ActionBooksPagesViewModel { Book = book, Genres = new SelectList(_genresRepository.GetAllGenres(), nameof(Genre.Id), nameof(Genre.Title), _genresRepository.GetAllGenres().FirstOrDefault(g => g.Id == book.GenreId)), PrevPageUrl = prevPageUrl })); } }