diff --git a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs index 3b5c8606b..260b0c651 100644 --- a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs +++ b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs @@ -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, IAsyncRequestHandler { - private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; public OrderProcessSaga( - OrderingContext orderingContext, - IOrderingIntegrationEventService orderingIntegrationEventService) + OrderingContext orderingContext) : base(orderingContext) { - _orderingIntegrationEventService = orderingIntegrationEventService; } /// @@ -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; diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index e25f285f9..58f1fe5f2 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -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()