/// <summary>
        /// Creates the specified order.
        /// </summary>
        /// <param name="orderSerialization">The order serialization.</param>
        /// <param name="args">The arguments.</param>
        public void Create(string orderSerialization, ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                VisitorOrderManager orderRepository = Context.Entity.Resolve <VisitorOrderManager>();
                var settings = new JsonSerializerSettings
                {
                    ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                    MissingMemberHandling      = MissingMemberHandling.Ignore,
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects
                };
                settings.Error += this.DeserializationErrorHandler;

                Order order = JsonConvert.DeserializeObject <Order>(orderSerialization, settings);

                orderRepository.Create(order);

                PipelineArgs pipelineArgs = new PipelineArgs();
                pipelineArgs.CustomData.Add("orderNumber", order.OrderId);

                CorePipeline.Run("orderCreated", pipelineArgs);
            }
        }
        /// <summary>
        /// Gets the product price matrix.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The product price matrix.</returns>
        public string GetPriceMatrix(string code, ServiceClientArgs args)
        {
            Assert.ArgumentNotNullOrEmpty(code, "code");
              Assert.ArgumentNotNull(args, "args");

              SiteContext site = Utils.GetExistingSiteContext(args);
              Database contentDatabase = site.ContentDatabase;
              Assert.IsNotNull(contentDatabase, "Unable to resolve content database.");

              using (new SiteContextSwitcher(site))
              {
            using (new SiteIndependentDatabaseSwitcher(contentDatabase))
            {
              IProductRepository productRepository = Context.Entity.Resolve<IProductRepository>();

              var repository = productRepository as ProductRepository;
              if (repository != null)
              {
            repository.Database = contentDatabase;
              }

              ProductPriceBaseData productPrice = productRepository.Get<ProductPriceBaseData>(code);

              return productPrice.PriceMatrix;
            }
              }
        }
Esempio n. 3
0
 /// <summary>
 /// Sets the customer id.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <param name="orderManager">The order manager.</param>
 internal static void SetCustomerId(ServiceClientArgs args, object orderManager)
 {
     if (orderManager is IUserAware)
       {
     ((IUserAware)orderManager).CustomerId = args.CustomerId;
       }
 }
 /// <summary>
 /// Generates the specified args.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns>The string.</returns>
 public string Generate(ServiceClientArgs args)
 {
     SiteContext site = Utils.GetExistingSiteContext(args);
       using (new SiteContextSwitcher(site))
       {
     OrderIDGenerator orderIdGenerator = Context.Entity.Resolve<OrderIDGenerator>();
     return orderIdGenerator.Generate();
       }
 }
        /// <summary>
        /// Gets the specified product stock.
        /// </summary>
        /// <param name="stockInfo">The stock info.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The product stock.</returns>
        public ProductStock Get(ProductStockInfo stockInfo, ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IProductStockManager stockManager = Context.Entity.Resolve<IProductStockManager>();

            return stockManager.GetStock(stockInfo);
              }
        }
        /// <summary>
        /// Generates the specified args.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The string.</returns>
        public string Generate(ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                OrderIDGenerator orderIdGenerator = Context.Entity.Resolve <OrderIDGenerator>();
                return(orderIdGenerator.Generate());
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Generates the order number.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The order number.</returns>
        public virtual string GenerateOrderNumber(ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();

                return(orderManager.GenerateOrderNumber());
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the specified product stock.
        /// </summary>
        /// <param name="stockInfo">The stock info.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The product stock.</returns>
        public ProductStock Get(ProductStockInfo stockInfo, ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>();

                return(stockManager.GetStock(stockInfo));
            }
        }
        /// <summary>
        /// Updates the specified product stock.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="newAmount">The new amount.</param>
        /// <param name="args">The arguments.</param>
        public void Update(string code, long newAmount, ServiceClientArgs args)
        {
            ProductStockInfo stockInfo = new ProductStockInfo { ProductCode = code };

              SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IProductStockManager stockManager = Context.Entity.Resolve<IProductStockManager>();

            stockManager.Update(stockInfo, newAmount);
              }
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the orders count.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The orders count.</returns>
        public int GetCount(Query query, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(query, "query");

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();
                Utils.SetCustomerId(args, orderManager);

                return(orderManager.GetOrdersCount(query));
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Updates the specified product stock.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="newAmount">The new amount.</param>
        /// <param name="args">The arguments.</param>
        public void Update(string code, long newAmount, ServiceClientArgs args)
        {
            ProductStockInfo stockInfo = new ProductStockInfo {
                ProductCode = code
            };

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>();

                stockManager.Update(stockInfo, newAmount);
            }
        }
        /// <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>
        /// 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);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Gets the by query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The orders.</returns>
        public DataTable GetRangeByQuery(Query query, int pageIndex, int pageSize, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(query, "query");

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();
                Utils.SetCustomerId(args, orderManager);

                IEnumerable <Order> orders = orderManager.GetOrders(query, pageIndex, pageSize);

                return(this.OrderConvertor.DomainModelToDTO(orders));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="orderNumber">The order number.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The string.</returns>
        public virtual DataTable Get(string orderNumber, ServiceClientArgs args)
        {
            Assert.ArgumentNotNullOrEmpty(orderNumber, "orderNumber");

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();
                Utils.SetCustomerId(args, orderManager);

                Order order = orderManager.GetOrder(orderNumber);

                return(this.OrderConvertor.DomainModelToDTO(order));
            }
        }
Esempio n. 16
0
        public static SiteContext GetExistingSiteContext([NotNull] ServiceClientArgs args)
        {
            Debug.ArgumentNotNull(args, "args");

            Assert.IsNotNullOrEmpty(args.SiteName, "Site name reqired.");

            SiteContext site = SiteContextFactory.GetSiteContext(args.SiteName);

            Assert.IsNotNull(site, "Unable to resolve site.");

            VisitorShopResolvingProcessor shopReolver = new VisitorShopResolvingProcessor();

            using (new SiteContextSwitcher(site))
            {
                shopReolver.Process(new PipelineArgs());
            }

            return(site);
        }
Esempio n. 17
0
        /// <summary>
        /// Saves the specified order.
        /// </summary>
        /// <param name="orderData">The order data.</param>
        /// <param name="args">The arguments.</param>
        public virtual void Save(DataTable orderData, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(orderData, "orderData");

            Assert.IsNotNull(orderData.Rows, "orderDataRow");
            Assert.IsTrue(orderData.Rows.Count == 1, "Order data expected.");

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();

                Order order = Context.Entity.Resolve <Order>();
                this.OrderConvertor.DTOToDomainModel(orderData.Rows[0], ref order);

                orderManager.SaveOrder(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));
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Creates the order.
        /// </summary>
        /// <param name="shoppingCartData">The shopping cart data.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The order.</returns>
        public virtual DataTable Create(DataTable shoppingCartData, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(shoppingCartData, "shoppingCartData");

            Assert.IsNotNull(shoppingCartData.Rows, "shoppingCartDataRow");
            Assert.IsTrue(shoppingCartData.Rows.Count == 1, "Shopping Cart data expected.");

            SiteContext site = Utils.GetExistingSiteContext(args);

            using (new SiteContextSwitcher(site))
            {
                ShoppingCart shoppingCart = Context.Entity.Resolve <ShoppingCart>();

                this.ShoppingCartConvertor.DTOToDomainModel(shoppingCartData.Rows[0], ref shoppingCart);

                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();
                Order order = orderManager.CreateOrder(shoppingCart);

                return(this.OrderConvertor.DomainModelToDTO(order));
            }
        }
        /// <summary>
        /// Creates the specified order.
        /// </summary>
        /// <param name="orderSerialization">The order serialization.</param>
        /// <param name="args">The arguments.</param>
        public void Create(string orderSerialization, ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            VisitorOrderManager orderRepository = Context.Entity.Resolve<VisitorOrderManager>();
            var settings = new JsonSerializerSettings
            {
              ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
              MissingMemberHandling = MissingMemberHandling.Ignore,
              PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };
            settings.Error += this.DeserializationErrorHandler;

            Order order = JsonConvert.DeserializeObject<Order>(orderSerialization, settings);

            orderRepository.Create(order);

            PipelineArgs pipelineArgs = new PipelineArgs();
            pipelineArgs.CustomData.Add("orderNumber", order.OrderId);

            CorePipeline.Run("orderCreated", pipelineArgs);
              }
        }
        /// <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);
              }
        }
Esempio n. 22
0
        /// <summary>
        /// Saves the specified order.
        /// </summary>
        /// <param name="orderData">The order data.</param>
        /// <param name="args">The arguments.</param>
        public virtual void Save(DataTable orderData, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(orderData, "orderData");

              Assert.IsNotNull(orderData.Rows, "orderDataRow");
              Assert.IsTrue(orderData.Rows.Count == 1, "Order data expected.");

              SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IOrderManager<Order> orderManager = Context.Entity.Resolve<IOrderManager<Order>>();

            Order order = Context.Entity.Resolve<Order>();
            this.OrderConvertor.DTOToDomainModel(orderData.Rows[0], ref order);

            orderManager.SaveOrder(order);
              }
        }
Esempio n. 23
0
        /// <summary>
        /// Gets the by query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The orders.</returns>
        public DataTable GetRangeByQuery(Query query, int pageIndex, int pageSize, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(query, "query");

              SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IOrderManager<Order> orderManager = Context.Entity.Resolve<IOrderManager<Order>>();
            Utils.SetCustomerId(args, orderManager);

            IEnumerable<Order> orders = orderManager.GetOrders(query, pageIndex, pageSize);

            return this.OrderConvertor.DomainModelToDTO(orders);
              }
        }
Esempio n. 24
0
        /// <summary>
        /// Gets the orders count.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The orders count.</returns>
        public int GetCount(Query query, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(query, "query");

              SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IOrderManager<Order> orderManager = Context.Entity.Resolve<IOrderManager<Order>>();
            Utils.SetCustomerId(args, orderManager);

            return orderManager.GetOrdersCount(query);
              }
        }
Esempio n. 25
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="orderNumber">The order number.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The string.</returns>
        public virtual DataTable Get(string orderNumber, ServiceClientArgs args)
        {
            Assert.ArgumentNotNullOrEmpty(orderNumber, "orderNumber");

              SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IOrderManager<Order> orderManager = Context.Entity.Resolve<IOrderManager<Order>>();
            Utils.SetCustomerId(args, orderManager);

            Order order = orderManager.GetOrder(orderNumber);

            return this.OrderConvertor.DomainModelToDTO(order);
              }
        }
Esempio n. 26
0
        /// <summary>
        /// Generates the order number.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The order number.</returns>
        public virtual string GenerateOrderNumber(ServiceClientArgs args)
        {
            SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            IOrderManager<Order> orderManager = Context.Entity.Resolve<IOrderManager<Order>>();

            return orderManager.GenerateOrderNumber();
              }
        }
Esempio n. 27
0
        /// <summary>
        /// Creates the order.
        /// </summary>
        /// <param name="shoppingCartData">The shopping cart data.</param>
        /// <param name="args">The arguments.</param>
        /// <returns>The order.</returns>
        public virtual DataTable Create(DataTable shoppingCartData, ServiceClientArgs args)
        {
            Assert.ArgumentNotNull(shoppingCartData, "shoppingCartData");

              Assert.IsNotNull(shoppingCartData.Rows, "shoppingCartDataRow");
              Assert.IsTrue(shoppingCartData.Rows.Count == 1, "Shopping Cart data expected.");

              SiteContext site = Utils.GetExistingSiteContext(args);
              using (new SiteContextSwitcher(site))
              {
            ShoppingCart shoppingCart = Context.Entity.Resolve<ShoppingCart>();

            this.ShoppingCartConvertor.DTOToDomainModel(shoppingCartData.Rows[0], ref shoppingCart);

            IOrderManager<Order> orderManager = Context.Entity.Resolve<IOrderManager<Order>>();
            Order order = orderManager.CreateOrder(shoppingCart);

            return this.OrderConvertor.DomainModelToDTO(order);
              }
        }