public async Task UpdateBook(Book book) { dbContext.Entry(book).State = EntityState.Modified; await dbContext.SaveChangesAsync(); }
public async Task<ActionResult> Create(Book book) { if (ModelState.IsValid) { //If author already exists var matchedAuthors = await authorDb.GetAllAuthors(); var author = matchedAuthors.FirstOrDefault(a => a.First_Name.ToUpper() == book.Author.First_Name.ToUpper() && a.Last_Name.ToUpper() == book.Author.Last_Name.ToUpper()); //then do not create new author, use existing instead if (author != null) book.Author = author; await bookDb.InsertBook(book); return RedirectToAction("ListBooks"); } return View(book); }
public async Task InsertBook(Book book) { dbContext.Books.Add(book); await dbContext.SaveChangesAsync(); }
public async Task<ActionResult> Edit(Book book) { ViewBag.Message = "Edit Book"; if (ModelState.IsValid) { await bookDb.UpdateBook(book); return RedirectToAction("ListBooks"); } return View(book); }