public ActionResult Edit(int id, BookAutherViewModel viewModel) { try { // TODO: Add update logic here string fileName = ChangeFile(viewModel.File, viewModel.imgUrl); var auther = autherRepository.Find(viewModel.AutherID); Book book = new Book { id = viewModel.BookID, Title = viewModel.Title, Description = viewModel.Description, _auther = auther, imgURL = fileName }; bookRepository.Update(id, book); return(RedirectToAction(nameof(Index))); } catch (Exception e) { return(View()); } }
public ActionResult Create(BookAutherViewModel model) { if (ModelState.IsValid) { try { string fileName = UploadFile(model.File) ?? string.Empty; if (model.AutherId == -1) { ViewBag.Message = "please select auther"; // var vmodel = new BookAutherViewModel { Authers = FillSelectList() }; return(View(GetAllAuther())); } // TODO: Add insert logic here var auther = autherRepo.Find(model.AutherId); Books book = new Books { Id = model.BookId, Tital = model.Titel, Auther = auther, ImageUrl = fileName }; bookRepo.Add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } // var vvmodel = new BookAutherViewModel { Authers = FillSelectList() }; ModelState.AddModelError("", "You have to fill all required fields !!"); return(View(GetAllAuther())); }
public ActionResult Edit(BookAutherViewModel model) { if (ModelState.IsValid) { try { string fileName = UploadFile(model.File, model.ImageUrl) ?? string.Empty; // TODO: Add update logic here var auther = autherRepo.Find(model.AutherId); Books book = new Books { Tital = model.Titel, Auther = auther, ImageUrl = fileName, Id = model.BookId }; bookRepo.Update(model.BookId, book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } ModelState.AddModelError("", "You have to fill all required fields !!"); return(View(GetAllAuther())); }
BookAutherViewModel GetAllAuther() { var model = new BookAutherViewModel { Authers = FillSelectList() }; return(model); }
// GET: BookController/Create public ActionResult Create() { var model = new BookAutherViewModel { Authers = FullListAuthers() }; return(View(model)); }
BookAutherViewModel fillList() { var vmodel = new BookAutherViewModel { Authers = FullListAuthers() }; return(vmodel); }
BookAutherViewModel GetModel() { var model = new BookAutherViewModel { authors = GetAuthors() }; return(model); }
// GET: Books/Edit/5 public ActionResult Edit(int id) { var book = bookRepo.Find(id); var autherId = book.Auther == null? book.Auther.Id = 0 : book.Auther.Id; //var autherId = book.Auther.Id; var ViewModel = new BookAutherViewModel { BookId = book.Id, Titel = book.Tital, AutherId = autherId, Authers = autherRepo.List().ToList(), ImageUrl = book.ImageUrl }; return(View(ViewModel)); }
BookAutherViewModel GetAllAuthers() { var authers = autherRepository.List().ToList(); authers.Insert(0, new Auther { id = -1, FullName = "Please Select an Auther" }); var model = new BookAutherViewModel { Authers = authers }; return(model); }
// GET: Book/Edit/5 public ActionResult Edit(int id) { var book = bookRepository.Find(id); var viewModel = new BookAutherViewModel { BookID = book.id, Title = book.Title, Description = book.Description, AutherID = book._auther.id, Authers = autherRepository.List().ToList(), imgUrl = book.imgURL }; return(View(viewModel)); }
// GET: BookController/Edit/5 public ActionResult Edit(int id) { var book = bookRepository.Find(id); var viewModel = new BookAutherViewModel { bookID = book.ID, Title = book.Title, Description = book.description, autherID = book.Auther.id, Authers = AutherRepository.List().ToList(), ImageURL = book.ImageURL }; return(View(viewModel)); }
// GET: Book/Edit/5 private BookAutherViewModel Get_BookAutherView_model(int id) { var book = bookRepository.Find(id); int author_id = book.auther == null ? 0 : book.auther.id; var book_model = new BookAutherViewModel { book_id = book.id, book_name = book.title, book_description = book.description, author_id = author_id, image_path = book.image_path, authors = GetAuthors() }; return(book_model); }
public ActionResult Edit(int id, BookAutherViewModel uBook) { try { if (uBook.author_id == -1) { ViewBag.message = "Please select an auther"; return(View(Get_BookAutherView_model(id))); } string image = string.Empty; if (uBook.image != null) { string images_folder_path = Path.Combine(hosting.ContentRootPath, "Content"); image = uBook.image.FileName; string path = Path.Combine(images_folder_path, image); using (var fileStream = new FileStream(path, FileMode.Create)) { uBook.image.CopyTo(fileStream); } } Console.WriteLine("dddd " + image); string previousImage = bookRepository.Find(id).image_path; string _Path = "Content/" + previousImage; Console.WriteLine("dddd " + _Path); FileInfo file = new FileInfo(_Path); if (file.Exists) { file.Delete(); } var book = new Book { auther = authorRepository.Find(uBook.author_id), id = uBook.book_id, description = uBook.book_description, title = uBook.book_name, image_path = image }; bookRepository.Update(id, book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Create(BookAutherViewModel book) { if (ModelState.IsValid) { try { string image = string.Empty; if (book.image != null) { string images_folder_path = Path.Combine(hosting.ContentRootPath, "Content"); image = book.image.FileName; string path = Path.Combine(images_folder_path, image); using (var fileStream = new FileStream(path, FileMode.Create)) { book.image.CopyTo(fileStream); } } // Console.WriteLine(image); if (book.author_id == -1) { ViewBag.message = "Please select an auther"; return(View(GetModel())); } var author = authorRepository.Find(book.author_id); var new_book = new Book { id = book.book_id, description = book.book_description, title = book.book_name, auther = author, image_path = image }; bookRepository.Add(new_book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } return(View(GetModel())); }
public ActionResult Edit(int id, BookAutherViewModel model) { try { string filename = UploadFile(model.File, model.ImageURL); Book book = new Book { ID = model.bookID, Title = model.Title, description = model.Description, Auther = AutherRepository.Find(model.autherID), ImageURL = filename }; bookRepository.update(model.bookID, book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Create(BookAutherViewModel model) { if (ModelState.IsValid) { try { if (model.AutherID == -1) { ViewBag.Message = "Please Select an Auther"; return(View(GetAllAuthers())); } DeleteFile(model.imgUrl); string fileName = UploadFile(model.File); var auther = autherRepository.Find(model.AutherID); // TODO: Add insert logic here Book book = new Book { Title = model.Title, Description = model.Description, _auther = auther, imgURL = fileName }; bookRepository.Add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } ModelState.AddModelError("", "You have to fill all the required fields!"); return(View(GetAllAuthers())); }
public ActionResult Create(BookAutherViewModel model) { if (ModelState.IsValid) { try { string filename = UploadFile(model.File) ?? String.Empty; if (model.autherID == -1) { ViewBag.Message = "please select an auther from the list"; return(View(fillList())); } Book book = new Book { Title = model.Title, description = model.Description, Auther = AutherRepository.Find(model.autherID), ImageURL = model.File.FileName }; bookRepository.add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } ModelState.AddModelError("", "You have to fill all the required fields"); return(View(fillList())); }