SaveChangesAsync() from Integration events
This commit is contained in:
parent
a5b0fd31cb
commit
d59ee8e817
@ -20,6 +20,8 @@
|
|||||||
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
|
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
|
||||||
|
|
||||||
orderToUpdate.SetCancelledStatus();
|
orderToUpdate.SetCancelledStatus();
|
||||||
|
|
||||||
|
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
|
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
|
||||||
|
|
||||||
orderToUpdate.SetPaidStatus();
|
orderToUpdate.SetPaidStatus();
|
||||||
|
|
||||||
|
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,6 +20,8 @@
|
|||||||
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
|
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
|
||||||
|
|
||||||
orderToUpdate.SetStockConfirmedStatus();
|
orderToUpdate.SetStockConfirmedStatus();
|
||||||
|
|
||||||
|
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,6 +26,8 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
|||||||
.Select(c => c.ProductId);
|
.Select(c => c.ProductId);
|
||||||
|
|
||||||
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
|
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
|
||||||
|
|
||||||
|
await _orderRepository.UnitOfWork.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -43,15 +43,14 @@ namespace Ordering.API.Application.Sagas
|
|||||||
/// period has completed.
|
/// period has completed.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns></returns>
|
/// <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);
|
CheckValidSagaId(orderSaga);
|
||||||
|
|
||||||
if (orderSaga.OrderStatus != OrderStatus.Cancelled)
|
if (orderSaga.OrderStatus != OrderStatus.Cancelled)
|
||||||
{
|
{
|
||||||
orderSaga.SetAwaitingValidationStatus();
|
orderSaga.SetAwaitingValidationStatus();
|
||||||
|
|
||||||
await SaveChangesAsync();
|
await SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
// but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour.
|
// but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour.
|
||||||
private readonly List<OrderItem> _orderItems;
|
private readonly List<OrderItem> _orderItems;
|
||||||
|
|
||||||
public IEnumerable<OrderItem> OrderItems => _orderItems.AsReadOnly();
|
public IReadOnlyList<OrderItem> OrderItems => _orderItems;
|
||||||
// Using List<>.AsReadOnly()
|
// Using List<>.AsReadOnly()
|
||||||
// This will create a read only wrapper around the private list so is protected against "external updates".
|
// 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)
|
// 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();
|
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)
|
public void SetStockConfirmedStatus(IEnumerable<int> orderStockNotConfirmedItems = null)
|
||||||
@ -121,15 +121,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
if (orderStockNotConfirmedItems is null)
|
if (orderStockNotConfirmedItems is null)
|
||||||
{
|
{
|
||||||
OrderStatus = OrderStatus.StockConfirmed;
|
|
||||||
|
|
||||||
_description = "All the items were confirmed with available stock.";
|
|
||||||
|
|
||||||
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id));
|
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id));
|
||||||
|
|
||||||
|
_orderStatusId = OrderStatus.StockConfirmed.Id;
|
||||||
|
_description = "All the items were confirmed with available stock.";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OrderStatus = OrderStatus.Cancelled;
|
_orderStatusId = OrderStatus.Cancelled.Id;
|
||||||
|
|
||||||
var itemsStockNotConfirmedProductNames = OrderItems
|
var itemsStockNotConfirmedProductNames = OrderItems
|
||||||
.Where(c => orderStockNotConfirmedItems.Contains(c.ProductId))
|
.Where(c => orderStockNotConfirmedItems.Contains(c.ProductId))
|
||||||
@ -147,10 +146,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
StatusChangeException();
|
StatusChangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems));
|
||||||
|
|
||||||
_orderStatusId = OrderStatus.Paid.Id;
|
_orderStatusId = OrderStatus.Paid.Id;
|
||||||
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\"";
|
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\"";
|
||||||
|
|
||||||
AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetShippedStatus()
|
public void SetShippedStatus()
|
||||||
@ -162,8 +161,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
_orderStatusId = OrderStatus.Shipped.Id;
|
_orderStatusId = OrderStatus.Shipped.Id;
|
||||||
_description = "";
|
_description = "";
|
||||||
|
|
||||||
//Call Domain Event
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCancelledStatus()
|
public void SetCancelledStatus()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user