Ejemplo n.º 1
0
        public OrderPartHandler(
            IRepository<OrderPartRecord> repository,
            IContentManager contentManager,
            IRepository<OrderDetailRecord> orderDetailsRepository,
            IOrdersService ordersService,
            IRepository<OrderAddressRecord> orderAddressRepository)
        {
            _orderDetailsRepository = orderDetailsRepository;

            Filters.Add(StorageFilter.For(repository));

            OnActivated<OrderPart>((context, part) => {
                // Details
                part._details.Loader(details => _orderDetailsRepository.Fetch(d => d.OrderId == part.Id)
                    .Select(d => new OrderDetail(d))
                    .ToList());

                // Order total
                part._orderTotal.Loader(orderTotal => BuildOrderTotal(part));

                // BillingAddress
                part._billingAddress.Loader(shippingAddress => orderAddressRepository.Get(part.BillingAddressId));
            });

            OnLoading<OrderPart>((context, part) => {
                // Order total
                part._orderTotal.Loader(orderTotal => part.Retrieve(x => x.OrderTotal));
            });

            OnCreating<OrderPart>((context, part) => {
                if (String.IsNullOrWhiteSpace(part.Reference)) {
                    part.Reference = ordersService.BuildOrderReference();
                }
            });

            OnCreated<OrderPart>((context, part) => {
                // Order total
                part.OrderTotal = BuildOrderTotal(part);

                SaveDetails(part);
                part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress);
            });

            OnUpdated<OrderPart>((context, part) => {
                // Order total
                part.OrderTotal = BuildOrderTotal(part);

                SaveDetails(part);
                part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress);
            });
        }
Ejemplo n.º 2
0
        public OrderPartHandler(
            IRepository <OrderPartRecord> repository,
            IContentManager contentManager,
            IRepository <OrderDetailRecord> orderDetailsRepository,
            IOrdersService ordersService,
            IRepository <OrderAddressRecord> orderAddressRepository,
            IOrderEventHandler orderEventHandler)
        {
            Filters.Add(StorageFilter.For(repository));

            OnActivated <OrderPart>((context, part) => {
                // Details
                part._details.Loader(details => orderDetailsRepository.Fetch(d => d.OrderId == part.Id)
                                     .Select(d => new OrderDetail(d))
                                     .ToList());

                // Order total
                part._orderTotal.Loader(orderTotal => BuildOrderTotal(part));

                // BillingAddress
                part._billingAddress.Loader(shippingAddress => orderAddressRepository.Get(part.BillingAddressId));
            });

            OnLoading <OrderPart>((context, part) => {
                // Order total
                part._orderTotal.Loader(orderTotal => part.Retrieve(x => x.OrderTotal));
            });

            OnCreating <OrderPart>((context, part) => {
                if (String.IsNullOrWhiteSpace(part.Reference))
                {
                    part.Reference = ordersService.BuildOrderReference();
                }
            });

            OnCreated <OrderPart>((context, part) => {
                // Order total
                part.OrderTotal = BuildOrderTotal(part);

                SaveDetails(part, orderDetailsRepository, orderEventHandler);
                part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress);

                orderEventHandler.OrderCreated(context.ContentItem);
            });

            OnUpdating <OrderPart>((context, part) => {
                // Status
                part.OriginalStatus = part.OrderStatus;
            });

            OnUpdated <OrderPart>((context, part) => {
                // Order total
                part.OrderTotal = BuildOrderTotal(part);

                SaveDetails(part, orderDetailsRepository, orderEventHandler);
                part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress);

                if (part.OrderStatus != part.OriginalStatus)
                {
                    switch (part.OrderStatus)
                    {
                    case OrderStatus.Canceled:
                        orderEventHandler.OrderCanceled(context.ContentItem);
                        break;

                    case OrderStatus.Completed:
                        orderEventHandler.OrderCompleted(context.ContentItem);
                        break;
                    }
                }
            });
        }