public static Model.Order.Shipment ToWebModel(this VirtoCommerceOrderModuleWebModelShipment shipment) { var webModel = new Model.Order.Shipment(); var currency = new Currency(EnumUtility.SafeParse(shipment.Currency, CurrencyCodes.USD)); webModel.InjectFrom(shipment); if (shipment.ChildrenOperations != null) { webModel.ChildrenOperations = shipment.ChildrenOperations.Select(co => co.ToWebModel()).ToList(); } webModel.Currency = currency; if (shipment.DeliveryAddress != null) { webModel.DeliveryAddress = shipment.DeliveryAddress.ToWebModel(); } if (shipment.Discount != null) { webModel.Discount = shipment.Discount.ToWebModel(); } webModel.DiscountAmount = new Money(shipment.DiscountAmount ?? 0, currency.Code); if (shipment.DynamicProperties != null) { webModel.DynamicProperties = shipment.DynamicProperties.Select(dp => dp.ToWebModel()).ToList(); } if (shipment.InPayments != null) { webModel.InPayments = shipment.InPayments.Select(p => p.ToWebModel()).ToList(); } if (shipment.Items != null) { webModel.Items = shipment.Items.Select(i => i.ToWebModel()).ToList(); } if (shipment.Packages != null) { webModel.Packages = shipment.Packages.Select(p => p.ToWebModel()).ToList(); } webModel.Sum = new Money(shipment.Sum ?? 0, currency.Code); webModel.Tax = new Money(shipment.Tax ?? 0, currency.Code); if (shipment.TaxDetails != null) { webModel.TaxDetails = shipment.TaxDetails.Select(td => td.ToWebModel()).ToList(); } return(webModel); }
public static Model.Order.Shipment ToWebModel(this VirtoCommerceOrderModuleWebModelShipment shipment, IEnumerable <Currency> availCurrencies, Language language) { var webModel = new Model.Order.Shipment(); var currency = availCurrencies.FirstOrDefault(x => x.Equals(shipment.Currency)) ?? new Currency(language, shipment.Currency); webModel.InjectFrom(shipment); if (shipment.ChildrenOperations != null) { webModel.ChildrenOperations = shipment.ChildrenOperations.Select(co => co.ToWebModel(availCurrencies, language)).ToList(); } webModel.Currency = currency; if (shipment.DeliveryAddress != null) { webModel.DeliveryAddress = shipment.DeliveryAddress.ToWebModel(); } if (shipment.Discount != null) { webModel.Discount = shipment.Discount.ToWebModel(availCurrencies, language); } webModel.DiscountAmount = new Money(shipment.DiscountAmount ?? 0, currency); if (shipment.DynamicProperties != null) { webModel.DynamicProperties = shipment.DynamicProperties.Select(dp => dp.ToWebModel()).ToList(); } if (shipment.InPayments != null) { webModel.InPayments = shipment.InPayments.Select(p => p.ToWebModel(availCurrencies, language)).ToList(); } if (shipment.Items != null) { webModel.Items = shipment.Items.Select(i => i.ToWebModel(availCurrencies, language)).ToList(); } if (shipment.Packages != null) { webModel.Packages = shipment.Packages.Select(p => p.ToWebModel(availCurrencies, language)).ToList(); } webModel.Sum = new Money(shipment.Sum ?? 0, currency); webModel.Tax = new Money(shipment.Tax ?? 0, currency); if (shipment.TaxDetails != null) { webModel.TaxDetails = shipment.TaxDetails.Select(td => td.ToWebModel(currency)).ToList(); } return(webModel); }