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