80 lines
2.9 KiB
C#
Raw Normal View History

namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using System;
using System.Collections.Generic;
2017-01-12 17:09:23 -08:00
//(CDLTLL)
//TO DO: Need to add additional Domain Logic to this Aggregate-Root for
//scenarios related to Order state changes, stock availability validation, etc.
public class Order
: Entity, IAggregateRoot
{
public int BuyerId { get; private set; }
public Buyer Buyer { get; private set; }
public DateTime OrderDate { get; private set; }
2016-11-22 18:40:47 +01:00
public int StatusId { get; private set; }
public OrderStatus Status { get; private set; }
2016-12-14 18:23:57 +01:00
public ICollection<OrderItem> OrderItems { get; private set; }
2016-11-22 18:40:47 +01:00
public int? ShippingAddressId { get; private set; }
public Address ShippingAddress { get; private set; }
2016-11-22 18:40:47 +01:00
public int PaymentId { get; private set; }
public Payment Payment { get; private set; }
protected Order() { }
public Order(int buyerId, int paymentId)
{
BuyerId = buyerId;
PaymentId = paymentId;
StatusId = OrderStatus.InProcess.Id;
OrderDate = DateTime.UtcNow;
2016-12-14 18:23:57 +01:00
OrderItems = new List<OrderItem>();
}
public void SetAddress(Address address)
{
if (address == null)
{
throw new ArgumentNullException(nameof(address));
}
ShippingAddress = address;
}
2016-12-14 18:23:57 +01:00
2017-01-19 19:51:28 -08:00
//TO DO:
// (CDLTLL) Bad implementation, needs to be changed.
// The AddOrderItem should have the needed data params
// instead of an already created OrderItem object.
// The Aggregate-Root is responsible for any Update/Creation of its child entities
// If we are providing an already created OrderItem, that was created from the outside
// and the AggregateRoot cannot control/validate any rule/invariants/consistency.
2016-12-14 18:23:57 +01:00
public void AddOrderItem(OrderItem item)
{
2017-01-19 19:51:28 -08:00
//TO DO: Bad implementation, need to change.
// The code "new OrderItem(params);" should be done here
// Plus any validation/rule related
2016-12-14 18:23:57 +01:00
OrderItems.Add(item);
2017-01-19 19:51:28 -08:00
//(CDLTLL)
// TO DO: Some more logic needs to be added here,
// Like consolidating items that are the same product in one single OrderItem with several units
// Also validation logic could be added here (like ensuring it is adding at least one item unit)
//Or, If there are different amounts of discounts per added OrderItem
//but the product Id is the same to existing Order Items, you should
//apply the higher discount, or any other domain logic that makes sense.
2016-12-14 18:23:57 +01:00
}
}
}