Exemple #1
0
        /// <summary>
        /// Runs the processor.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public virtual void Process([NotNull] PipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            object orderNumber = args.CustomData["orderNumber"];

            Assert.IsNotNull(orderNumber, "OrderNumber cannot be null.");

            VisitorOrderManager orderRepository = Context.Entity.Resolve <VisitorOrderManager>();

            Assert.IsNotNull(orderRepository, "OrderManager cannot be null.");

            string orderId = orderNumber.ToString();
            Order  order   = orderRepository.GetAll().SingleOrDefault(o => (o != null) && (o.OrderId == orderId));

            Assert.IsNotNull(order, "Order cannot be null.");

            OrderConfirmation orderConfirmation = Context.Entity.Resolve <OrderConfirmation>();

            Assert.IsNotNull(orderConfirmation, "OrderConfirmation cannot be null.");
            Assert.IsNotNull(orderConfirmation.ConfirmationMessageBuilder, "OrderConfirmation.ConfirmationMessageBuilder cannot be null.");

            orderConfirmation.ConfirmationMessageBuilder.Order = order;

            orderConfirmation.Send();
        }
        /// <summary>
        /// Cancels the order.
        /// </summary>
        /// <param name="orderNumber">The order number.</param>
        /// <param name="args">The arguments.</param>
        public void CancelOrder(string orderNumber, ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                VisitorOrderManager       orderManager          = Context.Entity.Resolve <VisitorOrderManager>();
                VisitorOrderProcessorBase visitorOrderProcessor = Context.Entity.Resolve <VisitorOrderProcessorBase>();

                Utils.SetCustomerId(args, orderManager);

                Order order = orderManager.GetAll().FirstOrDefault(o => o.OrderId == orderNumber);
                Assert.IsNotNull(order, "order cannot be null.");
                visitorOrderProcessor.CancelOrder(order);
            }
        }
        /// <summary>
        /// Gets all orders.
        /// </summary>
        /// <param name="filterExpression">The ExpressionSerializer expression.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>
        /// The all orders.
        /// </returns>
        public string GetAll(string filterExpression, ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                VisitorOrderManager orderRepository = Context.Entity.Resolve <VisitorOrderManager>();
                Utils.SetCustomerId(args, orderRepository);

                var    tempResult = orderRepository.GetAll();
                object rawResult  = this.ExpressionSerializer.ApplyExpressionAsFilter(tempResult, filterExpression);
                var    settings   = new JsonSerializerSettings
                {
                    ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                    MissingMemberHandling      = MissingMemberHandling.Ignore,
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects
                };
                return(JsonConvert.SerializeObject(rawResult, Formatting.None, settings));
            }
        }