|
@ -25,6 +25,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
|
|
|
|
|
private string _description; |
|
|
private string _description; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draft orders have this set to true. Currently we don't check anywhere the draft status of an Order, but we could do it if needed
|
|
|
|
|
|
private bool _isDraft; |
|
|
|
|
|
|
|
|
// DDD Patterns comment
|
|
|
// DDD Patterns comment
|
|
|
// Using a private collection field, better for DDD Aggregate's encapsulation
|
|
|
// Using a private collection field, better for DDD Aggregate's encapsulation
|
|
|
// so OrderItems cannot be added from "outside the AggregateRoot" directly to the collection,
|
|
|
// so OrderItems cannot be added from "outside the AggregateRoot" directly to the collection,
|
|
@ -34,12 +38,21 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
|
|
|
|
|
private int? _paymentMethodId; |
|
|
private int? _paymentMethodId; |
|
|
|
|
|
|
|
|
protected Order() { _orderItems = new List<OrderItem>(); } |
|
|
|
|
|
|
|
|
public static Order NewDraft() |
|
|
|
|
|
{ |
|
|
|
|
|
var order = new Order(); |
|
|
|
|
|
order._isDraft = true; |
|
|
|
|
|
return order; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Order() { |
|
|
|
|
|
_orderItems = new List<OrderItem>(); |
|
|
|
|
|
_isDraft = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber, |
|
|
public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber, |
|
|
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null) |
|
|
|
|
|
|
|
|
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null) : this() |
|
|
{ |
|
|
{ |
|
|
_orderItems = new List<OrderItem>(); |
|
|
|
|
|
_buyerId = buyerId; |
|
|
_buyerId = buyerId; |
|
|
_paymentMethodId = paymentMethodId; |
|
|
_paymentMethodId = paymentMethodId; |
|
|
_orderStatusId = OrderStatus.Submitted.Id; |
|
|
_orderStatusId = OrderStatus.Submitted.Id; |
|
@ -92,12 +105,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void SetAwaitingValidationStatus() |
|
|
public void SetAwaitingValidationStatus() |
|
|
{ |
|
|
|
|
|
|
|
|
{ |
|
|
if (_orderStatusId == OrderStatus.Submitted.Id) |
|
|
if (_orderStatusId == OrderStatus.Submitted.Id) |
|
|
{ |
|
|
{ |
|
|
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems)); |
|
|
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems)); |
|
|
_orderStatusId = OrderStatus.AwaitingValidation.Id; |
|
|
_orderStatusId = OrderStatus.AwaitingValidation.Id; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void SetStockConfirmedStatus() |
|
|
public void SetStockConfirmedStatus() |
|
@ -108,7 +121,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
|
|
|
|
|
_orderStatusId = OrderStatus.StockConfirmed.Id; |
|
|
_orderStatusId = OrderStatus.StockConfirmed.Id; |
|
|
_description = "All the items were confirmed with available stock."; |
|
|
_description = "All the items were confirmed with available stock."; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void SetPaidStatus() |
|
|
public void SetPaidStatus() |
|
@ -119,7 +132,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
|
|
|
|
|
_orderStatusId = OrderStatus.Paid.Id; |
|
|
_orderStatusId = OrderStatus.Paid.Id; |
|
|
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\""; |
|
|
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\""; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void SetShippedStatus() |
|
|
public void SetShippedStatus() |
|
@ -157,13 +170,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O |
|
|
|
|
|
|
|
|
var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames); |
|
|
var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames); |
|
|
_description = $"The product items don't have stock: ({itemsStockRejectedDescription})."; |
|
|
_description = $"The product items don't have stock: ({itemsStockRejectedDescription})."; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber, |
|
|
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber, |
|
|
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration) |
|
|
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration) |
|
|
{ |
|
|
{ |
|
|
var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, cardTypeId, |
|
|
|
|
|
|
|
|
var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, cardTypeId, |
|
|
cardNumber, cardSecurityNumber, |
|
|
cardNumber, cardSecurityNumber, |
|
|
cardHolderName, cardExpiration); |
|
|
cardHolderName, cardExpiration); |
|
|
|
|
|
|
|
|