Esempio n. 1
0
        public async Task <ActionResult> ModifyBooksFix2([FromRoute] int count = 100)
        {
            await ParallelizeAsync(async() =>
            {
                // DbContext options can be safely shared between threads,
                // so individual workers can create their own contexts using
                // shared options from DI.
                var newContext = new BookContext(_contextOptions);

                while (Interlocked.Decrement(ref count) >= 0)
                {
                    // Add a new book
                    var author    = await GetRandomAuthorAsync(newContext);
                    var book      = GetRandomBook(author);
                    var addedBook = await newContext.Books.AddAsync(book);
                    await newContext.SaveChangesAsync();

                    // Remove the book
                    newContext.Remove(addedBook.Entity);
                    await newContext.SaveChangesAsync();
                }
            });

            return(Ok());
        }
        public void Delete(int id)
        {
            var deletedEntity = _context.Find <TEntity>(id);

            _context.Remove(deletedEntity);
            _context.SaveChanges();
        }
Esempio n. 3
0
        public void Delete(Book deletedBook)
        {
            //
            _bookContext.Remove(deletedBook);

            _bookContext.SaveChanges();
        }
Esempio n. 4
0
        // DELETE api/values/5
        public HttpResponseMessage Delete(int id)
        {
            var book = db.Find <Book>(id);

            if (book == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponseModel()
                {
                    ErrorCode = HttpStatusCode.NotFound.ToString(), ErrorMessage = "Book with id wasn't founded."
                }));
            }

            db.Remove <Book>(book);

            db.SaveChanges();
            if (db.Find <Book>(id) == null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponseModel()
                {
                    ErrorCode = HttpStatusCode.NotFound.ToString(), ErrorMessage = "Book with id wasn't founded."
                }));
            }
        }
        public void Delete(Book deleteBook)
        {
            var currentBook = _bookContext.Books.FirstOrDefault(b => b.Id == deleteBook.Id);

            _bookContext.Remove(currentBook);
            _bookContext.SaveChanges();
        }
Esempio n. 6
0
        public IActionResult DeleteBook(int id)
        {
            Book bookToDelete = _context.Books.SingleOrDefault(b => b.BookId == id);

            _context.Remove(bookToDelete);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 7
0
        public IActionResult Delete(int id)
        {
            var det = _context.OrdeeDetails.Find(id);

            _context.Remove(det);
            _context.SaveChanges();
            return(RedirectToAction("ShowOrder"));
        }
Esempio n. 8
0
 public void Delete(int id)
 {
     using (BookContext db = new BookContext(config))
     {
         var dlt = db.Genres.Find(id);
         db.Remove(dlt);
         db.SaveChanges();
     }
 }
Esempio n. 9
0
        /// <summary>
        /// 本の削除
        /// </summary>
        /// <param name="autoNumber">削除対象データ</param>
        public IActionResult DeleteData(int autoNumber)
        {
            var target = this._dbContext.Book.FirstOrDefault(x => x.Autonumber == autoNumber);

            _dbContext.Remove(target);
            _dbContext.SaveChanges();

            return(new OkResult());
        }
Esempio n. 10
0
 public void Delete(int id)
 {
     using (context)
     {
         var myBook = context.MyBooks.Find(id);
         context.Remove(myBook);
         context.SaveChanges();
     }
 }
Esempio n. 11
0
        public void deleteName(int id)
        {
            Name name = context.Find <Name>(id);

            if (name != null)
            {
                context.Remove(name);
                context.SaveChanges();
            }
        }
Esempio n. 12
0
        public void Delete(Author deleteauthor)
        {
            // make sure the Author exists
            var currentBook = _bookContext.Books.FirstOrDefault(b => b.Id == deleteauthor.Id);

            if (currentBook != null)
            {
                _bookContext.Remove(deleteauthor);
                _bookContext.SaveChanges();
            }
        }
Esempio n. 13
0
        public void Delete(Book deletebook)
        {
            // make sure the book exists
            var currentBook = _bookContext.Books.FirstOrDefault(b => b.Id == deletebook.Id);

            if (currentBook != null)
            {
                _bookContext.Remove(deletebook);
                _bookContext.SaveChanges();
            }
        }
Esempio n. 14
0
        public void Remove(Book book)
        {
            var currentBook = _bookContext.Books.FirstOrDefault(b => b.Id == book.Id);

            if (currentBook == null)
            {
                return;
            }

            _bookContext.Remove(book);
            _bookContext.SaveChanges();
        }
Esempio n. 15
0
        public async Task Delete(int id)
        {
            var entity = await _bookContext.Books.FindAsync(id);

            if (entity == null)
            {
                throw new Exception("Book Doesn't Exist");
            }

            _bookContext.Remove(entity);
            await _bookContext.SaveChangesAsync();
        }
Esempio n. 16
0
        private static void DeleteUntrackedObject()
        {
            Book book = null;

            using (var context = new BookContext())
            {
                book = context.Books.FirstOrDefault();
            }

            using (var newContext = new BookContext())
            {
                newContext.GetService <ILoggerFactory>().AddProvider(new MyLoggerProvider());
                newContext.Remove(book);
                newContext.SaveChanges();
            }
        }
Esempio n. 17
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                Book book = await _context.Books.FindAsync(request.Id);

                if (book == null)
                {
                    throw new Exception("Não foi possível encontrar livro.");
                }

                _context.Remove(book);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Ocorreu um problema ao salvar os dados!");
            }
Esempio n. 18
0
        public async Task <ActionResult> ModifyBooks([FromRoute] int count = 100)
        {
            await ParallelizeAsync(async() =>
            {
                while (Interlocked.Decrement(ref count) >= 0)
                {
                    // Add a new book
                    var author    = await GetRandomAuthorAsync(_context);
                    var book      = GetRandomBook(author);
                    var addedBook = await _context.Books.AddAsync(book);
                    await _context.SaveChangesAsync();

                    // Remove the book
                    _context.Remove(addedBook.Entity);
                    await _context.SaveChangesAsync();
                }
            });

            return(Ok());
        }
Esempio n. 19
0
        public void EditBook(Book newBookDetails)
        {
            try
            {
                Book book = GetBookById(newBookDetails.Id);
                _context.Entry(book).CurrentValues.SetValues(newBookDetails);

                //remove or update child collection items
                var bookCategories = book.BookCategories;

                foreach (var bookCategory in bookCategories)
                {
                    var category = newBookDetails.BookCategories.SingleOrDefault(i => i.CategoryId == bookCategory.CategoryId);
                    if (category != null)
                    {
                        _context.Entry(bookCategory).CurrentValues.SetValues(category);
                    }
                    else
                    {
                        _context.Remove(category);
                    }
                }

                foreach (var category in newBookDetails.BookCategories)
                {
                    if (bookCategories.All(i => i.CategoryId != category.CategoryId))
                    {
                        book.BookCategories.Add(category);
                    }
                }
                _context.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
 public void Remove(Book book)
 {
     _bookContext.Remove(book);
     _bookContext.SaveChanges();
 }
Esempio n. 21
0
 public void Delete(int id)
 {
     bookContext.Remove(Find(id));
     bookContext.SaveChanges();
 }
Esempio n. 22
0
 public void Remove(Author removeAuthor)
 {
     _bookContext.Remove(removeAuthor);
     _bookContext.SaveChanges();
 }