Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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));
        }