Exemple #1
0
        public void Save(ECommerceDomain.Ordering.Order.Order order)
        {
            var orderLineDTOs = new List <OrderLineDTO>();

            foreach (var orderLine in order.OrderLines)
            {
                orderLineDTOs.Add(new OrderLineDTO
                {
                    SKU      = orderLine.SKU,
                    Quantity = orderLine.Quantity,
                    Price    = orderLine.Price
                });
            }

            var orderDTO = new OrderDTO
            {
                Created    = order.Created,
                CustomerId = order.CustomerId,
                Street     = order.ShippingAddress.Street,
                City       = order.ShippingAddress.City,
                State      = order.ShippingAddress.State,
                Country    = order.ShippingAddress.Country,
                Zipcode    = order.ShippingAddress.Zipcode,
                OrderLines = orderLineDTOs
            };

            _eCommerceContext.Orders.Add(orderDTO);

            foreach (var domainEvent in order.DomainEvents)
            {
                _eCommerceContext.AddDomainEvent(domainEvent);
            }

            order.ClearEvents();
        }
Exemple #2
0
        private ECommerceDomain.Ordering.Order.Order RehydrateOrder(OrderDTO orderDTO)
        {
            var customerDTO = orderDTO.CustomerDTO;

            var orderLines = new List <OrderLine>();

            foreach (var orderLineDto in orderDTO.OrderLines)
            {
                var orderLine = new OrderLine(orderLineDto.SKU, orderLineDto.Quantity, orderLineDto.Price);
                orderLines.Add(orderLine);
            }

            var shippingAddress = new Address(orderDTO.Street, orderDTO.City, orderDTO.State, orderDTO.Country,
                                              orderDTO.Zipcode);
            var billingAddress = new Address(orderDTO.Street, orderDTO.City, orderDTO.State, orderDTO.Country,
                                             orderDTO.Zipcode);

            var order = new ECommerceDomain.Ordering.Order.Order(orderDTO.Id, orderDTO.CustomerId, orderDTO.Created, shippingAddress, billingAddress, orderLines.AsReadOnly(), orderDTO.ShippingCost);

            return(order);
        }