public async Task <IActionResult> PutCategories(int id, Categories categories) { if (id != categories.CategoryId) { return(BadRequest()); } _context.Entry(categories).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBook([FromRoute] int id, [FromBody] Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.BookID) { return(BadRequest()); } _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Add([Bind("bookId,title,author,isbn,publisher,year")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("BookId,Title,Author")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("BookID,Title,PubDate,Category,AuthorID")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorID"] = new SelectList(_context.Set <Author>(), "AuthorID", "LastName", book.AuthorID); return(View(book)); }
public async Task <ActionResult> Create([Bind(Include = "ID,Name,PubDate,Price")] Book book) { if (ModelState.IsValid) { db.Books.Add(book); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(book)); }
public async Task <BookItems> AddItemsAsync(BookItems book) { var entity = new Book { Id = book.Id, Author = book.Author, Name = book.Name, Popular = book.Popular, Price = book.Price }; await _context.BookItems.AddAsync(entity); await _context.SaveChangesAsync(); book.Id = entity.Id; return(book); }
public async Task <int> Add(BookModel book) { var newBook = new Book() { AutherName = book.AutherName, BookName = book.BookName, Description = book.Description, LanguageId = book.LanguageId }; await _context.book.AddAsync(newBook); await _context.SaveChangesAsync(); return(newBook.Id); }