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)); } }
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)); } }