예제 #1
0
        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"));
        }
예제 #2
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                await _db.Book.AddAsync(book);

                await _db.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            else
            {
                return(Page());
            }
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }