public virtual async Task HandleEventAsync(ProductInventoryReductionAfterOrderPlacedResultEto eventData) { using (_currentTenant.Change(eventData.TenantId)) { var order = await _orderRepository.GetAsync(eventData.OrderId); if (order.OrderStatus != OrderStatus.Pending || order.ReducedInventoryAfterPlacingTime.HasValue) { return; } if (!eventData.IsSuccess) { // Todo: Cancel order. return; } order.SetReducedInventoryAfterPlacingTime(_clock.Now); await _orderRepository.UpdateAsync(order, true); } }
public virtual async Task HandleEventAsync(ProductInventoryReductionAfterOrderPlacedResultEto eventData) { using (_currentTenant.Change(eventData.TenantId)) { var order = await _orderRepository.GetAsync(eventData.OrderId); if (order.ReducedInventoryAfterPlacingTime.HasValue) { throw new OrderIsInWrongStageException(order.Id); } if (!eventData.IsSuccess) { await _orderManager.CancelAsync(order, OrdersConsts.InventoryReductionFailedAutoCancellationReason); return; } order.SetReducedInventoryAfterPlacingTime(_clock.Now); await _orderRepository.UpdateAsync(order, true); } }