public static Shipment ToShipment(this cartDto.CartShipment shipmentDto, ShoppingCart cart) { var retVal = new Shipment(cart.Currency) { Id = shipmentDto.Id, MeasureUnit = shipmentDto.MeasureUnit, ShipmentMethodCode = shipmentDto.ShipmentMethodCode, ShipmentMethodOption = shipmentDto.ShipmentMethodOption, WeightUnit = shipmentDto.WeightUnit, Height = shipmentDto.Height, Weight = shipmentDto.Weight, Width = shipmentDto.Width, Length = shipmentDto.Length, Currency = cart.Currency, Price = new Money(shipmentDto.Price ?? 0, cart.Currency), PriceWithTax = new Money(shipmentDto.PriceWithTax ?? 0, cart.Currency), DiscountAmount = new Money(shipmentDto.DiscountAmount ?? 0, cart.Currency), Total = new Money(shipmentDto.Total ?? 0, cart.Currency), TotalWithTax = new Money(shipmentDto.TotalWithTax ?? 0, cart.Currency), DiscountAmountWithTax = new Money(shipmentDto.DiscountAmountWithTax ?? 0, cart.Currency), TaxTotal = new Money(shipmentDto.TaxTotal ?? 0, cart.Currency), TaxPercentRate = (decimal?)shipmentDto.TaxPercentRate ?? 0m, TaxType = shipmentDto.TaxType }; if (shipmentDto.DeliveryAddress != null) { retVal.DeliveryAddress = ToAddress(shipmentDto.DeliveryAddress); } if (shipmentDto.Items != null) { retVal.Items = shipmentDto.Items.Select(i => ToShipmentItem(i, cart)).ToList(); } if (shipmentDto.TaxDetails != null) { retVal.TaxDetails = shipmentDto.TaxDetails.Select(td => ToTaxDetail(td, cart.Currency)).ToList(); } if (!shipmentDto.Discounts.IsNullOrEmpty()) { retVal.Discounts.AddRange(shipmentDto.Discounts.Select(x => ToDiscount(x, new[] { cart.Currency }, cart.Language))); } return(retVal); }
public static cartDto.CartShipment ToShipmentDto(this Shipment shipment) { var retVal = new cartDto.CartShipment { Id = shipment.Id, MeasureUnit = shipment.MeasureUnit, ShipmentMethodCode = shipment.ShipmentMethodCode, ShipmentMethodOption = shipment.ShipmentMethodOption, WeightUnit = shipment.WeightUnit, Height = shipment.Height, Weight = shipment.Weight, Width = shipment.Width, Length = shipment.Length, Currency = shipment.Currency != null ? shipment.Currency.Code : null, DiscountAmount = shipment.DiscountAmount != null ? (double?)shipment.DiscountAmount.InternalAmount : null, Price = shipment.Price != null ? (double?)shipment.Price.InternalAmount : null, TaxPercentRate = (double)shipment.TaxPercentRate, TaxType = shipment.TaxType }; if (shipment.DeliveryAddress != null) { retVal.DeliveryAddress = ToCartAddressDto(shipment.DeliveryAddress); } if (shipment.Discounts != null) { retVal.Discounts = shipment.Discounts.Select(ToCartDiscountDto).ToList(); } if (shipment.Items != null) { retVal.Items = shipment.Items.Select(ToShipmentItemDto).ToList(); } if (shipment.TaxDetails != null) { retVal.TaxDetails = shipment.TaxDetails.Select(ToCartTaxDetailDto).ToList(); } return(retVal); }