public ActionResult Edit(int id, Author author) { try { authorRepository.Update(id, author); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(int id, BookAuthorViewModel viewModel) { try { string fileName = Uploadfile(viewModel.File, viewModel.ImageUrl); //if (viewModel.File != null) //{ // var uploads = Path.Combine(hosting.WebRootPath, "uploads"); // fileName = Path.GetFileName(viewModel.File.FileName); // string fullPath = Path.Combine(uploads, fileName); // string oldFileName = viewModel.ImageUrl != null ? viewModel.ImageUrl : string.Empty; // string fullOldPath = Path.Combine(uploads, oldFileName); // if (fullOldPath != fullPath) // { // if (!System.IO.File.Exists(fullPath)) // { // viewModel.File.CopyTo(new FileStream(fullPath, FileMode.Create)); // } // } //} var author = authorRepository.find(viewModel.Author); var book = new Book { Id = viewModel.BookId, Title = viewModel.Title, Description = viewModel.Description, ImageUrl = fileName, Author = author }; bookRepository.Update(viewModel.BookId, book); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View()); } }