fix: Synchronize RemainingCount for Regular and Discount products in inventory commands
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m40s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m40s
This commit is contained in:
+20
@@ -41,6 +41,26 @@ public class IncreaseInventoryCommandHandler : IRequestHandler<IncreaseInventory
|
||||
};
|
||||
|
||||
await _context.StockMovements.AddAsync(stockMovement, cancellationToken);
|
||||
|
||||
// همگامسازی با Product.RemainingCount یا DiscountProduct.RemainingCount
|
||||
if (item.ProductType == ProductType.RegularProduct && item.ProductId.HasValue)
|
||||
{
|
||||
var product = await _context.Products.FindAsync(new object[] { item.ProductId.Value }, cancellationToken);
|
||||
if (product != null)
|
||||
{
|
||||
product.RemainingCount = item.Quantity;
|
||||
}
|
||||
}
|
||||
else if (item.ProductType == ProductType.DiscountProduct && item.DiscountProductId.HasValue)
|
||||
{
|
||||
var discountProduct = await _context.DiscountProducts.FindAsync(
|
||||
new object[] { item.DiscountProductId.Value }, cancellationToken);
|
||||
if (discountProduct != null)
|
||||
{
|
||||
discountProduct.RemainingCount = item.Quantity;
|
||||
}
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new IncreaseInventoryResponseDto
|
||||
|
||||
+20
@@ -65,6 +65,26 @@ public class ReduceInventoryCommandHandler : IRequestHandler<ReduceInventoryComm
|
||||
};
|
||||
|
||||
await _context.StockMovements.AddAsync(stockMovement, cancellationToken);
|
||||
|
||||
// همگامسازی با Product.RemainingCount یا DiscountProduct.RemainingCount
|
||||
if (item.ProductType == ProductType.RegularProduct && item.ProductId.HasValue)
|
||||
{
|
||||
var product = await _context.Products.FindAsync(new object[] { item.ProductId.Value }, cancellationToken);
|
||||
if (product != null)
|
||||
{
|
||||
product.RemainingCount = item.Quantity;
|
||||
}
|
||||
}
|
||||
else if (item.ProductType == ProductType.DiscountProduct && item.DiscountProductId.HasValue)
|
||||
{
|
||||
var discountProduct = await _context.DiscountProducts.FindAsync(
|
||||
new object[] { item.DiscountProductId.Value }, cancellationToken);
|
||||
if (discountProduct != null)
|
||||
{
|
||||
discountProduct.RemainingCount = item.Quantity;
|
||||
}
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new ReduceInventoryResponseDto { Success = true };
|
||||
|
||||
Reference in New Issue
Block a user