Browse Source

Update order saga cancel and ship commands

pull/809/head
Ramón Tomás 7 years ago
parent
commit
374c1d5317
2 changed files with 12 additions and 9 deletions
  1. +3
    -9
      src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs
  2. +9
    -0
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs

+ 3
- 9
src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs View File

@ -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;


+ 9
- 0
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -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…
Cancel
Save