public async Task <IActionResult> OnPostDelete(int id) { var book = await _db.Book.FindAsync(id); if (book == null) { return(NotFound()); } _db.Book.Remove(book); await _db.SaveChangesAsync(); return(RedirectToPage("Index")); }
public async Task <IActionResult> OnPost() { if (ModelState.IsValid) { await _db.Book.AddAsync(book); await _db.SaveChangesAsync(); return(RedirectToPage("Index")); } else { return(Page()); } }
public async Task <IActionResult> OnPost() { if (ModelState.IsValid) { var DBComingBook = await _db.Book.FindAsync(book.Id); DBComingBook.BookName = book.BookName; DBComingBook.Author = book.Author; DBComingBook.ISBN = book.ISBN; await _db.SaveChangesAsync(); return(RedirectToPage("Index")); } return(RedirectToPage()); }
public T Edit(T entity, int key) { if (entity == null) { return(null); } var existingObject = _context.Set <T>().Find(key); if (existingObject != null) { _context.Entry(existingObject).CurrentValues.SetValues(entity); _context.SaveChangesAsync(); } return(existingObject); }