public ActionResult Edit(BookAuthorViewModel viewModel) { try { // TODO: Add update logic here string fileName = UploadFile(viewModel.File, viewModel.ImageUrl); var author = authorRepository.Find(viewModel.AuthorId); Book book = new Book { Id = viewModel.BookId, Title = viewModel.Title, Description = viewModel.Description, Author = author, ImageUrl = fileName }; bookRepository.Update(viewModel.BookId, book); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View()); } }
public ActionResult Edit(int id, Author author) { try { authorRepository.Update(id, author); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(BookAuthorViewModel viewModel) { try { var author = authorRepository.Find(viewModel.AuthorId); Book book = new Book { Id = viewModel.BookId, Title = viewModel.Title, Description = viewModel.Description, Author = author, }; bookRepository.Update(book.Id, book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(BookAuthorViewModel viewModel) { try { string fileName = UploadFile(viewModel.File, viewModel.ImageUrl); //if (viewModel.File != null) //{ // string uploads = Path.Combine(hosting.WebRootPath, "uploads"); // fileName = viewModel.File.FileName; // string fullPath = Path.Combine(uploads, fileName); // //Delete the old file // string oldFileName = viewModel.ImageUrl; //bookRepository.Find(viewModel.BookId).ImageUrl; // string oldFullPath = Path.Combine(uploads, oldFileName); // if (fullPath != oldFullPath) // { // System.IO.File.Delete(oldFullPath); // //Save the new File // viewModel.File.CopyTo(new FileStream(fullPath, FileMode.Create)); // } //} // TODO: Add update logic here var author = authorRepository.Find(viewModel.AuthorId); Book book = new Book { Id = viewModel.BookId, Author = author, Description = viewModel.Description, Title = viewModel.Title, ImageUrl = fileName }; bookRepository.Update(viewModel.BookId, book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(int id, BookAuthorViewModel bookModel) { try { string fileName = UploadFile(bookModel.File, bookModel.ImageUrl); var author = authorRepo.Find(bookModel.AuthorId); Book book = new Book { Id = bookModel.BookId, Title = bookModel.Title, Description = bookModel.Description, Author = author, ImageUrl = fileName }; bookRepo.Update(bookModel.BookId, book); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View()); } }
public ActionResult Edit(BookAuthorViewModel viewModel) { string fileName = viewModel.ImageURL; // TODO: Add update logic here try { if (viewModel.File != null) { fileName = UploadFile(viewModel.File) ?? string.Empty; string oldFileName = viewModel.ImageURL; viewModel.ImageURL = ""; //Delete old file DeleteOldFile(oldFileName, viewModel.File.FileName); } var author = authorRepository.Find(viewModel.AuthorId); Book book = new Book { Id = viewModel.Id, Title = viewModel.Title, Description = viewModel.Description, Author = author, ImageURL = fileName }; bookRepository.Update(viewModel.Id, book); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View()); } }
public Book Update(Guid Id, Book book) { return(_iBookstoreRepository.Update(Id, book)); }