Example #1
0
        // Sample usage of factory and repository
        public void CreateNewOrder()
        {
            Client client = LoadClient(SystemUser.UserId);
            Order  order  = OrderFactory.CrateOrder(client);

            OrderRepository.Save(order);
        }
Example #2
0
        public void Handle(CreateOrderCommand command)
        {
            Client currentClient = ClientRepository.Load(SystemUser.UserId);

            Order order = OrderFactory.CrateOrder(currentClient);

            foreach (var productIdWithCount in command.ProductIdsWithCounts)
            {
                int productId = productIdWithCount.Key;
                int count     = productIdWithCount.Value;

                order.AddProduct(ProductRepository.Load(productId), count);

                ApplicationEventPublisher.Publish(new ProductAddedToOrderEvent(productId, SystemUser.UserId, count));
            }

            OrderRepository.Save(order);

            command.OrderId = order.Id;
        }