public void Delete(int id) { var entity = _context.Find <TEntity>(id); _context.Remove(entity); _context.SaveChanges(); }
public static int RemoveBooks(BookShopContext context) { var books = context.Books.Where(x => x.Copies <= 4200).ToList(); int removedCount = books.Count(); foreach (var book in books) { context.Remove(book); } context.SaveChanges(); return(removedCount); }
public static int RemoveBooks(BookShopContext context) { var booksForDeleting = context.Books.Where(x => x.Copies < 4200).ToArray(); foreach (var book in booksForDeleting) { context.Remove(book); } context.SaveChanges(); return(booksForDeleting.Length); }
//Problem 15 public static int RemoveBooks(BookShopContext context) { var books = context.Books.Where(c => c.Copies < 4200).ToArray(); int booksDeleted = 0; foreach (var book in books) { context.Remove(book); booksDeleted++; } return(booksDeleted); }
public async Task <ActionResult <Book> > Delete(int id) { Book book = dbContext.Books.FirstOrDefault(x => x.Id == id); if (book == null) { return(BadRequest()); } dbContext.Remove(book); await dbContext.SaveChangesAsync(); return(Ok(book)); }
public static int RemoveBooks(BookShopContext context) { var bookToRemove = context .Books .Where(b => b.Copies < 4200); foreach (var book in bookToRemove) { context.Remove(book); count++; } context.SaveChanges(); return(count); }
public static int RemoveBooks(BookShopContext context) { var result = 0; var booksToDelete = context.Books .Where(b => b.Copies < 4200); foreach (var b in booksToDelete) { result++; context.Remove(b); } context.SaveChanges(); return(result); }
//P15 public static int RemoveBooks(BookShopContext context) { var bookTitles = context.Books .Where(b => b.Copies < 4200) .ToArray(); int result = bookTitles.Count(); foreach (var book in bookTitles) { context.Remove(book); } context.SaveChanges(); return(result); }
public static int RemoveBooks(BookShopContext context) { var books = context.Books .Where(b => b.Copies < 4200) .ToList(); int counter = 0; foreach (var book in books) { context.Remove(book); counter += 1; } context.SaveChanges(); return(counter); }
//15. Remove Books public static int RemoveBooks(BookShopContext context) { var booksWithLessThan4200Coipies = context .Books .Where(b => b.Copies < 4200) .ToList(); int countOfDeletes = 0; foreach (var b in booksWithLessThan4200Coipies) { context.Remove(b); countOfDeletes++; } context.SaveChanges(); return(countOfDeletes); }
public async Task RemoveBookFromOrder(Guid orderId, Guid bookId) { var bookInOrder = await GetBookFromOrder(orderId, bookId); context.Remove(bookInOrder); }
public async Task RemoveOrder(Guid orderId) { var order = await GetOrder(orderId); context.Remove(order); }
public static int RemoveBooks(BookShopContext context) { var books = context.Books.Where(b => b.Copies < 4200).ToList(); context.BooksCategories.Where(b => books.Contains(b.Book)).ToList().ForEach(b => context.Remove(b)); books.ForEach(b => context.Books.Remove(b)); context.SaveChanges(); return(books.Count); }