public ActionResult Create(BookAuthorViewModel model) { try { if (model.Authorid == -1) { ViewBag.message = "Please select an athor"; var modela = new BookAuthorViewModel() { Authors = fillselectebox() }; return(View(modela)); } var author = authorrepository.Find(model.Authorid); book book = new book { Id = model.BookId, Title = model.BookName, Description = model.Description, Author = author }; bookrepository.Add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Create(Author author) { if (ModelState.IsValid) { try { authorRepository.Add(author); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } var authorv = new Author { Id = authorRepository.List().Max(a => a.Id) + 1, FullName = "" }; return(View(authorv)); }
public ActionResult Create(author author) { try { authorrepository.Add(author); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Create(BookAuthorViewModel bookauthor) { if (ModelState.IsValid) { try { string fileName = UploadFile(bookauthor.file) ?? string.Empty; if (bookauthor.AuthorId == -1) { ViewBag.message = "please choose an author"; var model = new BookAuthorViewModel() { Authors = FillSelectList() }; return(View(model)); } Book book = new Book { Description = bookauthor.Description, Title = bookauthor.Title, Author = authorRepository.Find(bookauthor.AuthorId), ImageUrl = fileName }; bookRepository.Add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } var modelv = new BookAuthorViewModel() { Authors = FillSelectList() }; return(View(modelv)); }