public async Task <IActionResult> Edit(BookAuthorCategoryModel model) { Book book = await db.Books.FirstOrDefaultAsync(u => u.Id == model.book.Id); book.AuthorId = model.book.AuthorId; book.Title = model.book.Title; db.Books.Update(book); await db.SaveChangesAsync(); return(RedirectToAction("Index", "Book")); }
public async Task <IActionResult> Add() { var authors = await db.Authors.ToListAsync(); var categories = await db.Categories.ToListAsync(); BookAuthorCategoryModel model = new BookAuthorCategoryModel { authors = authors }; return(View(model)); }
public async Task <IActionResult> Add(BookAuthorCategoryModel model) { Book book = new Book() { AuthorId = model.book.AuthorId, Title = model.book.Title, isFree = true }; db.Books.Add(book); await db.SaveChangesAsync(); return(RedirectToAction("EditCategory", new RouteValueDictionary( new { controller = "Book", action = "EditCategory", Id = book.Id }))); }
public async Task <IActionResult> EditCategory(int id) { Book book = await db.Books.FirstOrDefaultAsync(b => b.Id == id); var categories = await db.Categories.ToListAsync(); var bookCategories = await db.BookCategories.Where(b => b.BookId == id).ToListAsync(); BookAuthorCategoryModel model = new BookAuthorCategoryModel { book = book, categories = categories, bookCategories = bookCategories }; return(View(model)); }