SaveChangesAsync() from Integration events

This commit is contained in:
Christian Arenas 2017-05-16 15:11:03 +02:00
parent a5b0fd31cb
commit d59ee8e817
6 changed files with 19 additions and 15 deletions

View File

@ -20,6 +20,8 @@
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
orderToUpdate.SetCancelledStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

View File

@ -20,6 +20,8 @@
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
orderToUpdate.SetPaidStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

View File

@ -20,6 +20,8 @@
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
orderToUpdate.SetStockConfirmedStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

View File

@ -26,6 +26,8 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
.Select(c => c.ProductId);
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
await _orderRepository.UnitOfWork.SaveChangesAsync();
}
}
}

View File

@ -43,15 +43,14 @@ namespace Ordering.API.Application.Sagas
/// period has completed.
/// </param>
/// <returns></returns>
public async Task Handle(ConfirmGracePeriodCommandMsg @event)
public async Task Handle(ConfirmGracePeriodCommandMsg command)
{
var orderSaga = FindSagaById(@event.OrderId);
var orderSaga = FindSagaById(command.OrderId);
CheckValidSagaId(orderSaga);
if (orderSaga.OrderStatus != OrderStatus.Cancelled)
{
orderSaga.SetAwaitingValidationStatus();
await SaveChangesAsync();
}
}

View File

@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
// but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour.
private readonly List<OrderItem> _orderItems;
public IEnumerable<OrderItem> OrderItems => _orderItems.AsReadOnly();
public IReadOnlyList<OrderItem> OrderItems => _orderItems;
// Using List<>.AsReadOnly()
// This will create a read only wrapper around the private list so is protected against "external updates".
// It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance)
@ -107,9 +107,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
StatusChangeException();
}
_orderStatusId = OrderStatus.AwaitingValidation.Id;
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems));
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, OrderItems));
_orderStatusId = OrderStatus.AwaitingValidation.Id;
}
public void SetStockConfirmedStatus(IEnumerable<int> orderStockNotConfirmedItems = null)
@ -121,15 +121,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
if (orderStockNotConfirmedItems is null)
{
OrderStatus = OrderStatus.StockConfirmed;
_description = "All the items were confirmed with available stock.";
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id));
_orderStatusId = OrderStatus.StockConfirmed.Id;
_description = "All the items were confirmed with available stock.";
}
else
{
OrderStatus = OrderStatus.Cancelled;
_orderStatusId = OrderStatus.Cancelled.Id;
var itemsStockNotConfirmedProductNames = OrderItems
.Where(c => orderStockNotConfirmedItems.Contains(c.ProductId))
@ -147,10 +146,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
StatusChangeException();
}
AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems));
_orderStatusId = OrderStatus.Paid.Id;
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\"";
AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems));
}
public void SetShippedStatus()
@ -162,8 +161,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
_orderStatusId = OrderStatus.Shipped.Id;
_description = "";
//Call Domain Event
}
public void SetCancelledStatus()