private Order( List <OrderProductData> orderProductsData, List <ProductPriceData> productPrices, string currency, List <ConversionRate> conversionRates ) { this._orderDate = SystemClock.Now; this.Id = new OrderId(Guid.NewGuid()); this._orderProducts = new List <OrderProduct>(); foreach (var orderProductData in orderProductsData) { var productPrice = productPrices.Single(x => x.ProductId == orderProductData.ProductId && x.Price.Currency == currency); var orderProduct = OrderProduct.CreateForProduct( productPrice, orderProductData.Quantity, currency, conversionRates); _orderProducts.Add(orderProduct); } this.CalculateOrderValue(); this._status = OrderStatus.Placed; }
private Order( List <OrderProductData> orderProductsData, List <Product> allProducts, string currency, List <ConversionRate> conversionRates ) { this._orderDate = DateTime.UtcNow; this.Id = new OrderId(Guid.NewGuid()); this._orderProducts = new List <OrderProduct>(); foreach (var orderProductData in orderProductsData) { var product = allProducts.Single(x => x.Id == orderProductData.ProductId); var orderProduct = OrderProduct.CreateForProduct( product, orderProductData.Quantity, currency, conversionRates); _orderProducts.Add(orderProduct); } this.CalculateOrderValue(); this._status = OrderStatus.Placed; }
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; }