|
|
@ -1,5 +1,6 @@ |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; |
|
|
|
using Ordering.Domain.Events; |
|
|
|
using Ordering.Domain.Exceptions; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
@ -93,18 +94,38 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
_buyerId = id; |
|
|
|
} |
|
|
|
|
|
|
|
public void SetOrderStatusId(int id) |
|
|
|
#region Status Changes
|
|
|
|
public void SetSubmitedStatus() |
|
|
|
{ |
|
|
|
_orderStatusId = id; |
|
|
|
_orderStatusId = OrderStatus.Submited.Id; |
|
|
|
} |
|
|
|
|
|
|
|
public void SetAwaitingValidationStatus() |
|
|
|
{ |
|
|
|
if (_orderStatusId != OrderStatus.Submited.Id) |
|
|
|
{ |
|
|
|
StatusChangeException(); |
|
|
|
} |
|
|
|
|
|
|
|
_orderStatusId = OrderStatus.AwaitingValidation.Id; |
|
|
|
|
|
|
|
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, OrderItems)); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetOrderStockConfirmed(IEnumerable<int> orderStockNotConfirmedItems = null) |
|
|
|
public void SetStockConfirmedStatus(IEnumerable<int> orderStockNotConfirmedItems = null) |
|
|
|
{ |
|
|
|
if(orderStockNotConfirmedItems is null) |
|
|
|
if (_orderStatusId != OrderStatus.AwaitingValidation.Id) |
|
|
|
{ |
|
|
|
OrderStatus = OrderStatus.StockValidated; |
|
|
|
StatusChangeException(); |
|
|
|
} |
|
|
|
|
|
|
|
if (orderStockNotConfirmedItems is null) |
|
|
|
{ |
|
|
|
OrderStatus = OrderStatus.StockConfirmed; |
|
|
|
|
|
|
|
_description = "All the items were confirmed with available stock."; |
|
|
|
|
|
|
|
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@ -117,10 +138,36 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
var itemsStockNotConfirmedDescription = string.Join(", ", itemsStockNotConfirmedProductNames); |
|
|
|
_description = $"The product items don't have stock: ({itemsStockNotConfirmedDescription})."; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void SetPaidStatus() |
|
|
|
{ |
|
|
|
if (_orderStatusId != OrderStatus.StockConfirmed.Id) |
|
|
|
{ |
|
|
|
StatusChangeException(); |
|
|
|
} |
|
|
|
|
|
|
|
_orderStatusId = OrderStatus.Paid.Id; |
|
|
|
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\""; |
|
|
|
|
|
|
|
AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems)); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetShippedStatus() |
|
|
|
{ |
|
|
|
if (_orderStatusId != OrderStatus.Paid.Id) |
|
|
|
{ |
|
|
|
StatusChangeException(); |
|
|
|
} |
|
|
|
|
|
|
|
AddDomainEvent(new OrderStockConfirmedDomainEvent(Id, OrderStatus)); |
|
|
|
_orderStatusId = OrderStatus.Shipped.Id; |
|
|
|
_description = ""; |
|
|
|
|
|
|
|
//Call Domain Event
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber, |
|
|
|
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration) |
|
|
|
{ |
|
|
@ -130,6 +177,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
|
|
|
|
this.AddDomainEvent(orderStartedDomainEvent); |
|
|
|
} |
|
|
|
|
|
|
|
private void StatusChangeException() |
|
|
|
{ |
|
|
|
throw new OrderingDomainException("Not able to process order event. Reason: no valid order status change"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|