public ActionResult Create(AddBookFormModel addBookForm) { try { var author = new Author() { FirstName = addBookForm.AuthorFirstName, LastName = addBookForm.AuthorLastName }; var book = new Book { Title = addBookForm.Title, AuthorId = author.Id, YearPublished = addBookForm.YearPublished, Genre = addBookForm.Genre, //Location = addBookForm.Location }; repository.AddBook(book, author); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: Books/Create public ActionResult Create() { var bookLocations = new List <Location>(); AddBookFormModel model = new AddBookFormModel(); model.Locations = repository.GetLocations(); return(View(model)); }
public async Task <IActionResult> Add(AddBookFormModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await this.userManager.GetUserAsync(User); if (user == null) { return(NotFound()); } await this.books.AddAsync(model.Title, model.Description, user.Id); TempData.AddSuccessMessage($"Successfully added book {model.Title} by {user.UserName}"); return(this.RedirectToActionExtensionMethod(nameof(Index))); }