private async Task DeleteProduct(int productID, CancellationToken cancellationToken) { var product = await _dbContext.Products.FindAsync(productID); _dbContext.Products.Remove(product); await _dbContext.SaveChangesAsync(cancellationToken); }
public async Task Handle(OrderUpdatedV1Notification notification, CancellationToken cancellationToken) { var referencedProductIds = notification.OrderItems.Select(i => i.ProductID).ToArray(); var products = await _dbContext.Products.Where(i => referencedProductIds.Contains(i.ID) && i.HasOrders == false).ToListAsync(cancellationToken); foreach (var product in products) { product.HasOrders = true; } await _dbContext.SaveChangesAsync(cancellationToken); }
private async Task CreateProduct(Product product, CancellationToken cancellationToken) { _dbContext.Products.Add(product); await _dbContext.SaveChangesAsync(cancellationToken); }
private async Task UpdateProduct(Product product, CancellationToken cancellationToken) { _dbContext.Update(product); await _dbContext.SaveChangesAsync(cancellationToken); }