Example #1
0
        internal void Change(
            List <ProductPriceData> allProductPrices,
            List <OrderProductData> orderProductsData,
            List <ConversionRate> conversionRates,
            string currency)
        {
            foreach (OrderProductData orderProductData in orderProductsData)
            {
                ProductPriceData product = allProductPrices.Single(x => x.ProductId == orderProductData.ProductId &&
                                                                   x.Price.Currency == currency);

                OrderProduct existingProductOrder =
                    _orderProducts.SingleOrDefault(x => x.ProductId == orderProductData.ProductId);
                if (existingProductOrder != null)
                {
                    OrderProduct existingOrderProduct =
                        _orderProducts.Single(x => x.ProductId == existingProductOrder.ProductId);

                    existingOrderProduct.ChangeQuantity(product, orderProductData.Quantity, conversionRates);
                }
                else
                {
                    OrderProduct orderProduct = OrderProduct.CreateForProduct(product, orderProductData.Quantity,
                                                                              currency,
                                                                              conversionRates);
                    _orderProducts.Add(orderProduct);
                }
            }

            List <OrderProduct> orderProductsToCheck = _orderProducts.ToList();

            foreach (OrderProduct existingProduct in orderProductsToCheck)
            {
                OrderProductData product =
                    orderProductsData.SingleOrDefault(x => x.ProductId == existingProduct.ProductId);
                if (product == null)
                {
                    _orderProducts.Remove(existingProduct);
                }
            }

            CalculateOrderValue();

            _orderChangeDate = DateTime.UtcNow;
        }
        internal void Change(
            List <Product> allProducts,
            List <OrderProductData> orderProductsData,
            List <ConversionRate> conversionRates,
            string currency)
        {
            foreach (var orderProductData in orderProductsData)
            {
                var product = allProducts.Single(x => x.Id == orderProductData.ProductId);

                var existingProductOrder = _orderProducts.SingleOrDefault(x => x.ProductId == orderProductData.ProductId);
                if (existingProductOrder != null)
                {
                    var existingOrderProduct = this._orderProducts.Single(x => x.ProductId == existingProductOrder.ProductId);

                    existingOrderProduct.ChangeQuantity(product, orderProductData.Quantity, conversionRates);
                }
                else
                {
                    var orderProduct = OrderProduct.CreateForProduct(product, orderProductData.Quantity, currency, conversionRates);
                    this._orderProducts.Add(orderProduct);
                }
            }

            var orderProductsToCheck = _orderProducts.ToList();

            foreach (var existingProduct in orderProductsToCheck)
            {
                var product = orderProductsData.SingleOrDefault(x => x.ProductId == existingProduct.ProductId);
                if (product == null)
                {
                    this._orderProducts.Remove(existingProduct);
                }
            }

            this.CalculateOrderValue();

            this._orderChangeDate = DateTime.UtcNow;
        }