/// <summary>
        /// Gets (creates a new <see cref="IShipment"/>) from values saved in the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData"></param>
        public static IShipment GetShipment <T>(this ExtendedDataCollection extendedData) where T : LineItemBase
        {
            var origin             = extendedData.GetAddress(Constants.ExtendedDataKeys.ShippingOriginAddress);
            var destination        = extendedData.GetAddress(Constants.ExtendedDataKeys.ShippingDestinationAddress);
            var lineItemCollection = extendedData.GetLineItemCollection <T>();

            if (origin == null)
            {
                throw new NullReferenceException("ExtendedDataCollection does not contain an 'origin shipping address'");
            }
            if (destination == null)
            {
                throw new NullReferenceException("ExtendedDataCollection does not container a 'destination shipping address'");
            }
            if (lineItemCollection == null)
            {
                throw new NullReferenceException("ExtendedDataCollection does not contain a 'line item collection'");
            }

            return(new Shipment(origin, destination, lineItemCollection)
            {
                ShipMethodKey = extendedData.ContainsKey(Constants.ExtendedDataKeys.ShipMethodKey) ?
                                extendedData.GetShipMethodKey() :
                                Guid.Empty
            });
        }
Beispiel #2
0
        /// <summary>
        /// Gets (creates a new <see cref="IShipment"/>) from values saved in the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <typeparam name="T">
        /// The type of line item
        /// </typeparam>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <returns>
        /// The <see cref="IShipment"/>.
        /// </returns>
        public static IShipment GetShipment<T>(this ExtendedDataCollection extendedData)
            where T : LineItemBase
        {
            var origin = extendedData.GetAddress(Constants.ExtendedDataKeys.ShippingOriginAddress);
            var destination = extendedData.GetAddress(Constants.ExtendedDataKeys.ShippingDestinationAddress);
            var lineItemCollection = extendedData.GetLineItemCollection<T>();

            if (origin == null) throw new NullReferenceException("ExtendedDataCollection does not contain an 'origin shipping address'");
            if (destination == null) throw new NullReferenceException("ExtendedDataCollection does not container a 'destination shipping address'");
            if (lineItemCollection == null) throw new NullReferenceException("ExtendedDataCollection does not contain a 'line item collection'");

            // TODO - this is a total hack since this value can be changed in the database
            var quoted = new ShipmentStatus()
            {
                Key = Constants.DefaultKeys.ShipmentStatus.Quoted,
                Alias = "quoted",
                Name = "Quoted",
                Active = true,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            };

            return new Shipment(quoted, origin, destination, lineItemCollection)
                {
                    ShipMethodKey = extendedData.ContainsKey(Constants.ExtendedDataKeys.ShipMethodKey) ?
                        extendedData.GetShipMethodKey() :
                        Guid.Empty
                };
        }
Beispiel #3
0
        /// <summary>
        /// Gets an <see cref="IAddress"/> from the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <param name="addressType">
        /// The address Type.
        /// </param>
        /// <returns>
        /// The <see cref="IAddress"/>.
        /// </returns>
        public static IAddress GetAddress(this ExtendedDataCollection extendedData, AddressType addressType)
        {
            var address = extendedData.GetAddress(addressType == AddressType.Shipping
                                               ? Constants.ExtendedDataKeys.ShippingDestinationAddress
                                               : Constants.ExtendedDataKeys.BillingAddress);

            if (address != null)
            {
                address.AddressType = addressType;
            }

            return(address);
        }
 /// <summary>
 /// Gets an <see cref="IAddress"/> from the <see cref="ExtendedDataCollection"/>
 /// </summary>
 /// <param name="extendedData"></param>
 /// <param name="addressType"></param>
 /// <returns></returns>
 public static IAddress GetAddress(this ExtendedDataCollection extendedData, AddressType addressType)
 {
     return(extendedData.GetAddress(addressType == AddressType.Shipping
                                        ? Constants.ExtendedDataKeys.ShippingDestinationAddress
                                        : Constants.ExtendedDataKeys.BillingAddress));
 }