コード例 #1
0
        public void CreateOrder(OrderDto order)
        {
            Id           = Guid.NewGuid().ToString();
            ProductId    = order.ProductId;
            CustomerName = order.CustomerName;
            Quantity     = order.Quantity;
            ProductPrice = order.ProductPrice;
            DeliveryDate = order.DeliveryDate;
            OrderPrice   = Quantity * ProductPrice;
            if (DeliveryDate.ToUniversalTime() < DateTime.UtcNow)
            {
                throw new Exception("Order cannot be created for a past delivery date");
            }
            PlacedDate = DateTime.UtcNow;

            var orderCreatedEvent = new OrderCreatedEvent(this);

            AddEvent(orderCreatedEvent);
        }