|
|
@ -12,7 +12,7 @@ using System.Threading.Tasks; |
|
|
|
|
|
|
|
namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent |
|
|
|
{ |
|
|
|
public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler |
|
|
|
public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler |
|
|
|
: INotificationHandler<OrderStartedDomainEvent> |
|
|
|
{ |
|
|
|
private readonly ILoggerFactory _logger; |
|
|
@ -21,8 +21,8 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent |
|
|
|
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; |
|
|
|
|
|
|
|
public ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler( |
|
|
|
ILoggerFactory logger, |
|
|
|
IBuyerRepository buyerRepository, |
|
|
|
ILoggerFactory logger, |
|
|
|
IBuyerRepository buyerRepository, |
|
|
|
IIdentityService identityService, |
|
|
|
IOrderingIntegrationEventService orderingIntegrationEventService) |
|
|
|
{ |
|
|
@ -33,13 +33,13 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent |
|
|
|
} |
|
|
|
|
|
|
|
public async Task Handle(OrderStartedDomainEvent orderStartedEvent, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var cardTypeId = (orderStartedEvent.CardTypeId != 0) ? orderStartedEvent.CardTypeId : 1; |
|
|
|
var buyer = await _buyerRepository.FindAsync(orderStartedEvent.UserId); |
|
|
|
bool buyerOriginallyExisted = (buyer == null) ? false : true; |
|
|
|
|
|
|
|
if (!buyerOriginallyExisted) |
|
|
|
{ |
|
|
|
{ |
|
|
|
buyer = new Buyer(orderStartedEvent.UserId, orderStartedEvent.UserName); |
|
|
|
} |
|
|
|
|
|
|
@ -51,8 +51,8 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent |
|
|
|
orderStartedEvent.CardExpiration, |
|
|
|
orderStartedEvent.Order.Id); |
|
|
|
|
|
|
|
var buyerUpdated = buyerOriginallyExisted ? |
|
|
|
_buyerRepository.Update(buyer) : |
|
|
|
var buyerUpdated = buyerOriginallyExisted ? |
|
|
|
_buyerRepository.Update(buyer) : |
|
|
|
_buyerRepository.Add(buyer); |
|
|
|
|
|
|
|
await _buyerRepository.UnitOfWork |
|
|
@ -60,7 +60,6 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent |
|
|
|
|
|
|
|
var orderStatusChangedTosubmittedIntegrationEvent = new OrderStatusChangedToSubmittedIntegrationEvent(orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name); |
|
|
|
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedTosubmittedIntegrationEvent); |
|
|
|
|
|
|
|
_logger.CreateLogger<ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler>() |
|
|
|
.LogTrace("Buyer {BuyerId} and related payment method were validated or updated for orderId: {OrderId}.", |
|
|
|
buyerUpdated.Id, orderStartedEvent.Order.Id); |
|
|
|