Trying to understand how this can be modeled without breaking DDD rules.
This is a system for managing and sending Gift Cards to Customers
Customer
-------
CustomerId (Primary Key)
CustomerType
FirstName
LastName
GiftCard
------
GiftcardId (Primary Key)
ShopName
Suspended
CreatedDate
CustomerGift
-------------
CustomerId (Foreign Key -> Customer)
GiftcardId (Foreign Key -> Giftcard)
GiftDate
I have the following models
public class Customer
{
Int CustomerID;
String FirstName;
String LastName;
String CustomerType;
IEnumerable<CustomerGift> CustomerGifts;
}
public class CustomerGift
{
Int GiftCardID;
Int CustomerId;
DateTime GiftDate;
}
public class GiftCard
{
Int GiftCardID;
String ShopName;
Bool Suspended
DateTime CreatedDate;
}
Domain rules:
- GiftCards are bulk entered into the system and can be assigned at anytime
- A GiftCard can be suspended at anytime
- A GiftCard can be sent upto 50 customers
- A CustomerGift can be deleted at any time
- A Customer can be deleted at any time
- A Customer can receive upto N number of GiftCards depending on the customer type
To my understanding the Customer and GiftCards are aggrigate roots and the CustomerGift is a child.
However at its current state there is no way to enforce the "GiftCard can be sent upto 50 customers" rule without exposing the CustomerGift to the GiftCard. Which would break the rule by sharing a child entity.