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(); }
public void Delete(Book deletedBook) { // _bookContext.Remove(deletedBook); _bookContext.SaveChanges(); }
// 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(); }
public IActionResult DeleteBook(int id) { Book bookToDelete = _context.Books.SingleOrDefault(b => b.BookId == id); _context.Remove(bookToDelete); _context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Delete(int id) { var det = _context.OrdeeDetails.Find(id); _context.Remove(det); _context.SaveChanges(); return(RedirectToAction("ShowOrder")); }
public void Delete(int id) { using (BookContext db = new BookContext(config)) { var dlt = db.Genres.Find(id); db.Remove(dlt); db.SaveChanges(); } }
/// <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()); }
public void Delete(int id) { using (context) { var myBook = context.MyBooks.Find(id); context.Remove(myBook); context.SaveChanges(); } }
public void deleteName(int id) { Name name = context.Find <Name>(id); if (name != null) { context.Remove(name); context.SaveChanges(); } }
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(); } }
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(); } }
public void Remove(Book book) { var currentBook = _bookContext.Books.FirstOrDefault(b => b.Id == book.Id); if (currentBook == null) { return; } _bookContext.Remove(book); _bookContext.SaveChanges(); }
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(); }
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(); } }
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!"); }
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()); }
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(); }
public void Delete(int id) { bookContext.Remove(Find(id)); bookContext.SaveChanges(); }
public void Remove(Author removeAuthor) { _bookContext.Remove(removeAuthor); _bookContext.SaveChanges(); }