[ValidateAntiForgeryToken] //This is for protections from hackers
        public async Task <IActionResult> Edit(Book book)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            this.dbContext.Books.Update(book);

            await dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> OnPostDelete(int Id)
        {
            var book = await _db.Books.FindAsync(Id);

            if (book == null)
            {
                return(NotFound());
            }
            _db.Books.Remove(book);
            await _db.SaveChangesAsync();

            return(RedirectToPage("Index"));
        }
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                await _db.Books.AddAsync(Book);

                await _db.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            else
            {
                return(Page());
            }
        }
Exemple #4
0
        //-----

        public async Task <IActionResult> Delete(int id)
        {
            var dbCurrentBook = await _db.Book.FirstOrDefaultAsync(x => x.BookId == id);

            if (dbCurrentBook == null)
            {
                return(Json(new{ success = false, message = "The book was could not be deleted" }));
            }
            else
            {
                _db.Book.Remove(dbCurrentBook);
                await _db.SaveChangesAsync();

                return(Json(new { success = true, message = "The book was removed" }));
            }
        }
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var book = await _db.Books.FindAsync(Book.Id);

                book.Name   = Book.Name;
                book.Author = Book.Author;
                await _db.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            else
            {
                return(RedirectToPage("Index"));
            }
        }
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var currentBook = await _db.Book.FindAsync(Book.BookId);

                currentBook.BookName   = Book.BookName;
                currentBook.BookAuthor = Book.BookAuthor;
                currentBook.ISBN       = Book.ISBN;

                await _db.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            else
            {
                return(RedirectToPage());
            }
        }