public IActionResult EditBook(BookAdminFormViewModel model) { if (ModelState.IsValid) { if (model.Photo != null) { if (model.Book.PhotoName != null) { DeleteImage(model.Book.PhotoName); } model.Book.PhotoName = ProcessUploadedFile(model.Photo); } bookRepository.Update(model.Book); return(RedirectToAction("DisplayAllBooks")); } Book book = bookRepository.GetBook(model.Book.Id); IEnumerable <Category> allCategories = categoryRepository.GetAllCategories(); if (book == null) { ViewBag.Object = "Book"; return(View("Views/Home/ObjectNotFound.cshtml", model.Book.Id)); } BookAdminFormViewModel viewModel = new BookAdminFormViewModel { AllCategories = allCategories, Book = book }; return(View("Views/Admin/Book/EditBook.cshtml", viewModel)); }
public ViewResult CreateBook() { IEnumerable <Category> allCategories = categoryRepository.GetAllCategories(); BookAdminFormViewModel viewModel = new BookAdminFormViewModel { AllCategories = allCategories, Book = new Book() }; return(View("Views/Admin/Book/CreateBook.cshtml", viewModel)); }
public IActionResult EditBook(int id) { Book book = bookRepository.GetBook(id); IEnumerable <Category> allCategories = categoryRepository.GetAllCategories(); if (book == null) { ViewBag.Object = "Book"; return(View("Views/Home/ObjectNotFound.cshtml", id)); } BookAdminFormViewModel viewModel = new BookAdminFormViewModel { AllCategories = allCategories, Book = book }; return(View("Views/Admin/Book/EditBook.cshtml", viewModel)); }
public IActionResult CreateBook(BookAdminFormViewModel model) { if (ModelState.IsValid) { model.Book.PhotoName = ProcessUploadedFile(model.Photo); bookRepository.Add(model.Book); return(RedirectToAction("DisplayAllBooks")); } IEnumerable <Category> allCategories = categoryRepository.GetAllCategories(); BookAdminFormViewModel viewModel = new BookAdminFormViewModel { AllCategories = allCategories, Book = new Book() }; return(View("Views/Admin/Book/CreateBook.cshtml", viewModel)); }