public OrderDetailModel CreateOrderDetailModel(UOrder_Order from) { var to = new OrderDetailModel(); CopyOrderDetailModel(to, from); return(to); }
private void CopyOrderDetailModel(OrderDetailModel to, UOrder_Order from) { var toItems = CreateOrderDetailItemModels(from.MOrder.OrderItems); var toShipments = new List <OrderDetailShipmentModel>(); var fromShipments = from.MFulfillable?.Shipments; if (fromShipments != null) { foreach (var fromShipment in fromShipments) { var toShipment = new OrderDetailShipmentModel() { ShipmentDateTime = Locale.GetLocalTimeFromUtc(fromShipment.ShipmentDateTimeUtc), ShippingVendor = fromShipment.ShippingVendorId, TrackingCode = fromShipment.TrackingCode }; var toShipmentItems = new List <OrderDetailItemModel>(); foreach (var fromShipmentItem in fromShipment.ShipmentItems) { var fromOrderItemId = ParseOrderItemId.FromFulfillableItemReference(fromShipmentItem.FulfillableItemReference); var toItem = toItems.Where(r => r.OrderItemId == fromOrderItemId).Single(); toShipmentItems.Add(toItem); _ = toItems.Remove(toItem); } toShipment.Items = toShipmentItems; toShipments.Add(toShipment); } } var toReturns = new List <OrderDetailReturnModel>(); var fromReturns = from.MFulfillable?.Returns; if (fromReturns != null) { foreach (var fromReturn in fromReturns) { var toReturn = new OrderDetailReturnModel() { ReturnDateTime = Locale.GetLocalTimeFromUtc(fromReturn.CreateDateTimeUtc) }; var toReturnItems = new List <OrderDetailItemModel>(); foreach (var fromReturnItem in fromReturn.ReturnItems) { var fromOrderItemId = ParseOrderItemId.FromFulfillableItemReference(fromReturnItem.FulfillableItemReference); var toItem = toItems.Where(r => r.OrderItemId == fromOrderItemId).Single(); toReturnItems.Add(toItem); _ = toItems.Remove(toItem); } toReturn.Items = toReturnItems; toReturns.Add(toReturn); } } to.OrderId = from.MOrder.OrderId; to.OrderNumber = from.MOrder.OrderNumber; to.ItemSubtotal = from.MOrder.ItemSubtotalAmount; to.Shipping = from.MOrder.ShippingAmount; to.Discount = from.MOrder.DiscountAmount; to.TaxableAmount = from.MOrder.TaxableAmount; to.SalesTaxPercent = from.MOrder.SalesTaxPercent; to.SalesTax = from.MOrder.SalesTaxAmount; to.Total = from.MOrder.TotalAmount; to.OrderStatus = from.MOrder.OrderStatus.ToString(); to.StatusDateTime = Locale.GetLocalTimeFromUtc(from.MOrder.UpdateDateTimeUtc); to.SubmissionDateTime = Locale.GetLocalTimeFromUtc(from.MOrder.SubmissionDateTimeUtc); to.ShippingName = from.MOrder.ShippingAddress.Name; to.ShippingAddressLines = FormatAddress( from.MOrder.ShippingAddress.AddressLine1, from.MOrder.ShippingAddress.AddressLine2, from.MOrder.ShippingAddress.City, from.MOrder.ShippingAddress.StateCode, from.MOrder.ShippingAddress.PostalCode, from.MOrder.ShippingAddress.CountryCode).ToArray(); to.PendingItems = toItems; to.Shipments = toShipments; to.Returns = toReturns; to.CanCancel = from.MOrder.CanCancel; to.CanPay = from.MOrder.CanPay; to.CanReturn = from.MOrder.CanReturn; }