Exemple #1
0
        public IActionResult Update(AuthorVM authors)
        {
            if (ModelState.IsValid)
            {
                // if user doesnot uplaod new image
                String imagePath = _authourRepo.GetAuthorById(authors.author.id).image_path;


                // if the user Uploads new Image
                if (authors.image != null)
                {
                    // this class contains the function that handles the files
                    FileHandling fileHandling = new FileHandling(_hostEnvironment);
                    imagePath = fileHandling.fileUpload(authors.image, "authors");
                }


                authors.author.image_path = imagePath;
                _authourRepo.UpdateAuthor(authors.author);
                return(RedirectToAction("Table", authors));
            }
            else
            {
                return(View("UpdateForm", authors));
            }
        }
        public IActionResult Update(BookVM book)
        {
            if (ModelState.IsValid)
            {
                // if the image file is new updated
                String imagePath = _bookrepo.GetById(book.books.id).image_path;

                // if new image is updated
                if (book.image != null)
                {
                    // this class contains the function that handles the files
                    FileHandling fileHandling = new FileHandling(_webHostEnvironment);
                    imagePath = fileHandling.fileUpload(book.image, "books");
                }


                book.books.image_path = imagePath;
                _bookrepo.UpdateBook(book.books);
                return(RedirectToAction("Table", book));
            }
            else
            {
                book.fileError  = "Please Upload a Image";
                book.genreList  = _genreRepo.GetAllGenres();
                book.authorList = _authorRepo.GetAllAuthors();

                return(View("UpdateForm", book));
            }
        }
Exemple #3
0
        public IActionResult DeleteById(int id)
        {
            // first retrive the data
            Author authorToDelete = _authourRepo.GetAuthorById(id);

            //then delete the data from the database
            _authourRepo.DeleteAuthorById(id);

            // deleting the user file
            FileHandling fileHandling = new FileHandling(_hostEnvironment);

            fileHandling.deleteFile(authorToDelete.image_path, "authors");

            return(RedirectToAction("Table"));
        }
        public IActionResult DeleteById(int id)
        {
            // first retrive the data
            Book bookToDelete = _bookrepo.GetById(id);

            //then delete the data from the database
            _bookrepo.DeleteBookById(id);

            // deleting the user file
            FileHandling fileHandling = new FileHandling(_webHostEnvironment);

            fileHandling.deleteFile(bookToDelete.image_path, "books");

            return(RedirectToAction("Table"));
        }
Exemple #5
0
        public IActionResult Add(AuthorVM authors)
        {
            if (ModelState.IsValid && authors.image != null)
            {
                // this class contains the function that handles the files
                FileHandling fileHandling = new FileHandling(_hostEnvironment);
                String       imagePath    = fileHandling.fileUpload(authors.image, "authors");

                authors.author.image_path = imagePath;
                _authourRepo.AddAuthor(authors.author);
                return(RedirectToAction("Table", authors));
            }
            else
            {
                authors.fileError = "Please Upload a Image";
                return(View("AddForm", authors));
            }
        }