public async Task <IActionResult> Create(EditBookViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var book = new Book { Title = model.Title, BookAuthors = new List <BookAuthor>(model.SelectedAuthors.Select(a => new BookAuthor { AuthorId = a, BookId = model.Id })), Genres = new List <GenreEntry>(model.SelectedGenres.Select(g => new GenreEntry { GenreName = g, BookId = model.Id })) }; _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Name")] Genre genre) { if (ModelState.IsValid) { _context.Add(genre); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task <IActionResult> Create([Bind("Id,Name,Age,Phone")] Borrower borrower) { if (ModelState.IsValid) { _context.Add(borrower); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(borrower)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] Author author) { if (ModelState.IsValid) { _context.Add(author); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Create([Bind("BookId,Name,Author,Year")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }