public virtual CustomerOrder ToCustomerOrder(orderDto.CustomerOrder order, ICollection <Currency> availCurrencies, Language language) { var currency = availCurrencies.FirstOrDefault(x => x.Equals(order.Currency)) ?? new Currency(language, order.Currency); var result = new CustomerOrder(currency); result.InjectFrom <NullableAndEnumValueInjecter>(order); if (order.Addresses != null) { result.Addresses = order.Addresses.Select(ToAddress).ToList(); } if (order.DynamicProperties != null) { result.DynamicProperties = order.DynamicProperties.Select(ToDynamicProperty).ToList(); } if (order.InPayments != null) { result.InPayments = order.InPayments.Select(p => ToOrderInPayment(p, availCurrencies, language)).ToList(); } if (order.Items != null) { result.Items = order.Items.Select(i => ToOrderLineItem(i, availCurrencies, language)).ToList(); } if (order.Shipments != null) { result.Shipments = order.Shipments.Select(s => ToOrderShipment(s, availCurrencies, language)).ToList(); } if (!order.Discounts.IsNullOrEmpty()) { result.Discounts.AddRange(order.Discounts.Select(x => ToDiscount(x, new[] { currency }, language))); } if (order.TaxDetails != null) { result.TaxDetails = order.TaxDetails.Select(td => ToTaxDetail(td, currency)).ToList(); } result.DiscountAmount = new Money(order.DiscountAmount ?? 0, currency); result.Total = new Money(order.Total ?? 0, currency); result.SubTotal = new Money(order.SubTotal ?? 0, currency); result.SubTotalWithTax = new Money(order.SubTotalWithTax ?? 0, currency); result.TaxTotal = new Money(order.TaxTotal ?? 0, currency); result.ShippingTotal = new Money(order.ShippingTotal ?? 0, currency); result.ShippingTotalWithTax = new Money(order.ShippingTotalWithTax ?? 0, currency); result.ShippingTaxTotal = new Money(order.ShippingTaxTotal ?? 0, currency); result.SubTotalTaxTotal = new Money(order.SubTotalTaxTotal ?? 0, currency); result.SubTotalDiscount = new Money(order.SubTotalDiscount ?? 0, currency); result.SubTotalDiscountWithTax = new Money(order.SubTotalDiscountWithTax ?? 0, currency); return(result); }
public static CustomerOrder ToCustomerOrder(this orderDto.CustomerOrder order, IEnumerable <Currency> availCurrencies, Language language) { var currency = availCurrencies.FirstOrDefault(x => x.Equals(order.Currency)) ?? new Currency(language, order.Currency); var result = new CustomerOrder(currency) { CancelledDate = order.CancelledDate, CancelReason = order.CancelReason, ChannelId = order.ChannelId, Comment = order.Comment, CreatedBy = order.CreatedBy, CreatedDate = order.CreatedDate, CustomerId = order.CustomerId, CustomerName = order.CustomerName, EmployeeId = order.EmployeeId, EmployeeName = order.EmployeeName, Id = order.Id, IsApproved = order.IsApproved, IsCancelled = order.IsCancelled, ModifiedBy = order.ModifiedBy, ModifiedDate = order.ModifiedDate, Number = order.Number, OrganizationId = order.OrganizationId, OrganizationName = order.OrganizationName, Status = order.Status, StoreId = order.StoreId, StoreName = order.StoreName, SubscriptionNumber = order.SubscriptionNumber }; if (order.Addresses != null) { result.Addresses = order.Addresses.Select(ToAddress).ToList(); } if (order.DynamicProperties != null) { result.DynamicProperties = order.DynamicProperties.Select(ToDynamicProperty).ToList(); } if (order.InPayments != null) { result.InPayments = order.InPayments.Select(p => ToOrderInPayment(p, availCurrencies, language)).ToList(); } if (order.Items != null) { result.Items = order.Items.Select(i => ToOrderLineItem(i, availCurrencies, language)).ToList(); } if (order.Shipments != null) { result.Shipments = order.Shipments.Select(s => ToOrderShipment(s, availCurrencies, language)).ToList(); } if (!order.Discounts.IsNullOrEmpty()) { result.Discounts.AddRange(order.Discounts.Select(x => ToDiscount(x, new[] { currency }, language))); } if (order.TaxDetails != null) { result.TaxDetails = order.TaxDetails.Select(td => ToTaxDetail(td, currency)).ToList(); } result.DiscountAmount = new Money(order.DiscountAmount ?? 0, currency); result.DiscountTotal = new Money(order.DiscountTotal ?? 0, currency); result.DiscountTotalWithTax = new Money(order.DiscountTotalWithTax ?? 0, currency); result.PaymentTotal = new Money(order.PaymentTotal ?? 0, currency); result.PaymentTotalWithTax = new Money(order.PaymentTotalWithTax ?? 0, currency); result.PaymentDiscountTotal = new Money(order.PaymentDiscountTotal ?? 0, currency); result.PaymentDiscountTotalWithTax = new Money(order.PaymentDiscountTotalWithTax ?? 0, currency); result.PaymentTaxTotal = new Money(order.PaymentTaxTotal ?? 0, currency); result.PaymentPrice = new Money(order.PaymentSubTotal ?? 0, currency); result.PaymentPriceWithTax = new Money(order.PaymentSubTotalWithTax ?? 0, currency); result.Total = new Money(order.Total ?? 0, currency); result.SubTotal = new Money(order.SubTotal ?? 0, currency); result.SubTotalWithTax = new Money(order.SubTotalWithTax ?? 0, currency); result.TaxTotal = new Money(order.TaxTotal ?? 0, currency); result.ShippingTotal = new Money(order.ShippingTotal ?? 0, currency); result.ShippingTotalWithTax = new Money(order.ShippingTotalWithTax ?? 0, currency); result.ShippingTaxTotal = new Money(order.ShippingTaxTotal ?? 0, currency); result.ShippingPrice = new Money(order.ShippingSubTotal ?? 0, currency); result.ShippingPriceWithTax = new Money(order.ShippingSubTotalWithTax ?? 0, currency); result.SubTotalTaxTotal = new Money(order.SubTotalTaxTotal ?? 0, currency); result.SubTotalDiscount = new Money(order.SubTotalDiscount ?? 0, currency); result.SubTotalDiscountWithTax = new Money(order.SubTotalDiscountWithTax ?? 0, currency); return(result); }
public static CustomerOrder ToCustomerOrder(this orderDto.CustomerOrder orderDto, ICollection <Currency> availCurrencies, Language language) { return(OrderConverterInstance.ToCustomerOrder(orderDto, availCurrencies, language)); }