Update order saga cancel and ship commands
This commit is contained in:
parent
4e79875d26
commit
374c1d5317
@ -8,10 +8,7 @@ using Ordering.API.Application.Commands;
|
||||
using Ordering.API.Application.IntegrationCommands.Commands;
|
||||
using Ordering.API.Application.IntegrationEvents;
|
||||
using Ordering.Domain.Exceptions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Ordering.API.Application.IntegrationEvents;
|
||||
|
||||
namespace Ordering.API.Application.Sagas
|
||||
{
|
||||
@ -28,14 +25,11 @@ namespace Ordering.API.Application.Sagas
|
||||
IAsyncRequestHandler<CancelOrderCommand, bool>,
|
||||
IAsyncRequestHandler<ShipOrderCommand, bool>
|
||||
{
|
||||
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
|
||||
|
||||
public OrderProcessSaga(
|
||||
OrderingContext orderingContext,
|
||||
IOrderingIntegrationEventService orderingIntegrationEventService)
|
||||
OrderingContext orderingContext)
|
||||
: base(orderingContext)
|
||||
{
|
||||
_orderingIntegrationEventService = orderingIntegrationEventService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -79,7 +73,7 @@ namespace Ordering.API.Application.Sagas
|
||||
if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id
|
||||
|| orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id)
|
||||
{
|
||||
orderSaga.SetOrderStatusId(OrderStatus.Cancelled.Id);
|
||||
orderSaga.SetCancelStatus();
|
||||
result = await SaveChangesAsync();
|
||||
}
|
||||
return result;
|
||||
@ -101,7 +95,7 @@ namespace Ordering.API.Application.Sagas
|
||||
// its status is paid
|
||||
if (orderSaga.GetOrderStatusId() == OrderStatus.Paid.Id)
|
||||
{
|
||||
orderSaga.SetOrderStatusId(OrderStatus.Shipped.Id);
|
||||
orderSaga.SetShippedStatus();
|
||||
result = await SaveChangesAsync();
|
||||
}
|
||||
return result;
|
||||
|
@ -166,6 +166,15 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
//Call Domain Event
|
||||
}
|
||||
|
||||
public void SetCancelStatus()
|
||||
{
|
||||
if (_orderStatusId == OrderStatus.Shipped.Id)
|
||||
{
|
||||
throw new OrderingDomainException("Not possible to change order status. Reason: cannot cancel order it is already shipped");
|
||||
}
|
||||
_orderStatusId = OrderStatus.Cancelled.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public int GetOrderStatusId()
|
||||
|
Loading…
x
Reference in New Issue
Block a user