Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Shipment"/> class.
        /// </summary>
        /// <param name="shipmentStatus">
        /// The shipment Status.
        /// </param>
        /// <param name="origin">
        /// The origin.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="items">
        /// The items.
        /// </param>
        internal Shipment(IShipmentStatus shipmentStatus, IAddress origin, IAddress destination, LineItemCollection items)
        {
            Mandate.ParameterNotNull(shipmentStatus, "shipmentStatus");
            Mandate.ParameterNotNull(origin, "origin");
            Mandate.ParameterNotNull(destination, "destination");
            Mandate.ParameterNotNull(items, "items");

            _shippedDate      = DateTime.Now;
            _fromOrganization = origin.Organization;
            _fromName         = origin.Name;
            _fromAddress1     = origin.Address1;
            _fromAddress2     = origin.Address2;
            _fromLocality     = origin.Locality;
            _fromRegion       = origin.Region;
            _fromPostalCode   = origin.PostalCode;
            _fromCountryCode  = origin.CountryCode;
            _fromIsCommercial = origin.IsCommercial;
            _toOrganization   = destination.Organization;
            _toName           = destination.Name;
            _toAddress1       = destination.Address1;
            _toAddress2       = destination.Address2;
            _toLocality       = destination.Locality;
            _toRegion         = destination.Region;
            _toPostalCode     = destination.PostalCode;
            _toCountryCode    = destination.CountryCode;
            _toIsCommercial   = destination.IsCommercial;

            _phone = destination.Phone;
            _email = destination.Email;

            _shipmentStatus = shipmentStatus;
            _items          = items;
        }
Exemplo n.º 2
0
        internal ItemCache(Guid entityKey, Guid itemCacheTfKey, LineItemCollection items)
        {
            Mandate.ParameterCondition(entityKey != Guid.Empty, "entityKey");
            Mandate.ParameterCondition(itemCacheTfKey != Guid.Empty, "itemCacheTfKey");
            Mandate.ParameterNotNull(items, "items");

            _entityKey      = entityKey;
            _itemCacheTfKey = itemCacheTfKey;
            _items          = items;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Order"/> class.
        /// </summary>
        /// <param name="orderStatus">
        /// The order status.
        /// </param>
        /// <param name="invoiceKey">
        /// The invoice key.
        /// </param>
        /// <param name="lineItemCollection">
        /// The line item collection.
        /// </param>
        internal Order(IOrderStatus orderStatus, Guid invoiceKey, LineItemCollection lineItemCollection)
        {
            Mandate.ParameterNotNull(orderStatus, "orderStatus");
            Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey");
            Mandate.ParameterNotNull(lineItemCollection, "lineItemCollection");

            _invoiceKey  = invoiceKey;
            _orderStatus = orderStatus;
            _items       = lineItemCollection;

            _orderDate = DateTime.Now;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an instance of <see cref="LineItemCollection"/> from a serialized collection in the ExtendedDataCollection
        /// </summary>
        /// <typeparam name="T">The type of the <see cref="ILineItem"/></typeparam>
        /// <param name="extendedData">The extended data collection</param>
        /// <returns><see cref="LineItemCollection"/></returns>
        public static LineItemCollection GetLineItemCollection <T>(this ExtendedDataCollection extendedData) where T : LineItemBase
        {
            if (!extendedData.ContainsKey(Constants.ExtendedDataKeys.LineItemCollection))
            {
                return(null);
            }

            var xdoc = XDocument.Parse(extendedData.GetValue(Constants.ExtendedDataKeys.LineItemCollection));
            var lineItemCollection = new LineItemCollection();

            foreach (var element in xdoc.Descendants(Constants.ExtendedDataKeys.LineItem))
            {
                var dictionary = GetLineItemXmlValues(element.ToString());

                var extendData = new ExtendedDataCollection(dictionary[Constants.ExtendedDataKeys.ExtendedData]);

                var ctrValues = new object[]
                {
                    new Guid(dictionary[Constants.ExtendedDataKeys.LineItemTfKey]),
                    dictionary[Constants.ExtendedDataKeys.Name],
                    dictionary[Constants.ExtendedDataKeys.Sku],
                    int.Parse(dictionary[Constants.ExtendedDataKeys.Quantity]),
                    decimal.Parse(dictionary[Constants.ExtendedDataKeys.Price], NumberStyles.Any, CultureInfo.InvariantCulture),
                    new ExtendedDataCollection(dictionary[Constants.ExtendedDataKeys.ExtendedData])
                };

                var attempt = ActivatorHelper.CreateInstance <LineItemBase>(typeof(T).FullName, ctrValues);

                if (!attempt.Success)
                {
                    LogHelper.Error <LineItemCollection>("Failed to instantiate a LineItemCollection from ExtendedData", attempt.Exception);
                    throw attempt.Exception;
                }

                attempt.Result.ContainerKey = new Guid(dictionary[Constants.ExtendedDataKeys.ContainerKey]);

                lineItemCollection.Add(attempt.Result);
            }

            return(lineItemCollection);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Clones a shipment
        /// </summary>
        /// <param name="org">
        /// The org.
        /// </param>
        /// <returns>
        /// The <see cref="IShipment"/>.
        /// </returns>
        /// <remarks>
        /// http://issues.merchello.com/youtrack/issue/M-458
        /// </remarks>
        internal static IShipment Clone(this IShipment org)
        {
            var lineItemCollection = new LineItemCollection();

            foreach (var li in org.Items)
            {
                lineItemCollection.Add(li.AsLineItemOf <OrderLineItem>());
            }

            return(new Shipment(org.ShipmentStatus, org.GetOriginAddress(), org.GetDestinationAddress(), lineItemCollection)
            {
                ShipmentNumberPrefix = org.ShipmentNumberPrefix,
                ShipmentNumber = org.ShipmentNumber,
                ShippedDate = org.ShippedDate,
                TrackingCode = org.TrackingCode,
                Carrier = org.Carrier,
                ShipMethodKey = org.ShipMethodKey,
                Phone = org.Phone,
                Email = org.Email
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Invoice"/> class.
        /// </summary>
        /// <param name="invoiceStatus">
        /// The invoice status.
        /// </param>
        /// <param name="billToAddress">
        /// The bill to address.
        /// </param>
        /// <param name="lineItemCollection">
        /// The line item collection.
        /// </param>
        /// <param name="orders">
        /// The orders.
        /// </param>
        internal Invoice(IInvoiceStatus invoiceStatus, IAddress billToAddress, LineItemCollection lineItemCollection, OrderCollection orders)
        {
            Mandate.ParameterNotNull(invoiceStatus, "invoiceStatus");
            Mandate.ParameterNotNull(billToAddress, "billToAddress");
            Mandate.ParameterNotNull(lineItemCollection, "lineItemCollection");
            Mandate.ParameterNotNull(orders, "orders");

            _invoiceStatus = invoiceStatus;

            _billToName        = billToAddress.Name;
            _billToAddress1    = billToAddress.Address1;
            _billToAddress2    = billToAddress.Address2;
            _billToLocality    = billToAddress.Locality;
            _billToRegion      = billToAddress.Region;
            _billToPostalCode  = billToAddress.PostalCode;
            _billToCountryCode = billToAddress.CountryCode;
            _billToPhone       = billToAddress.Phone;

            _items       = lineItemCollection;
            _orders      = orders;
            _invoiceDate = DateTime.Now;
        }
        /// <summary>
        /// Adds a <see cref="LineItemCollection"/> to the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData"></param>
        /// <param name="lineItemCollection"></param>
        public static void AddLineItemCollection(this ExtendedDataCollection extendedData, LineItemCollection lineItemCollection)
        {
            using (var sw = new StringWriter())
            {
                var settings = new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                };

                using (var writer = XmlWriter.Create(sw, settings))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement(Constants.ExtendedDataKeys.LineItemCollection);

                    foreach (var lineItem in lineItemCollection)
                    {
                        //writer.WriteStartElement(Constants);
                        writer.WriteRaw(((LineItemBase)lineItem).SerializeToXml());
                    }

                    writer.WriteEndElement(); // ExtendedData
                    writer.WriteEndDocument();
                }
                extendedData.SetValue(Constants.ExtendedDataKeys.LineItemCollection, sw.ToString());
            }
        }
Exemplo n.º 8
0
 public ItemCache(Guid entityKey, ItemCacheType itemCacheType, LineItemCollection items)
     : this(entityKey, EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey, items)
 {
 }