Exemple #1
0
        internal static IShipment ToShipment(this ShipmentDisplay shipmentDisplay, IShipment destination)
        {
            if (shipmentDisplay.Key != Guid.Empty)
            {
                destination.Key = shipmentDisplay.Key;
            }
            destination.ShippedDate      = shipmentDisplay.ShippedDate;
            destination.FromOrganization = destination.FromOrganization;
            destination.FromName         = shipmentDisplay.FromName;
            destination.FromAddress1     = shipmentDisplay.FromAddress1;
            destination.FromAddress2     = shipmentDisplay.FromAddress2;
            destination.FromLocality     = shipmentDisplay.FromLocality;
            destination.FromRegion       = shipmentDisplay.FromRegion;
            destination.FromPostalCode   = shipmentDisplay.FromPostalCode;
            destination.FromCountryCode  = shipmentDisplay.FromCountryCode;
            destination.FromIsCommercial = shipmentDisplay.FromIsCommercial;
            destination.ToOrganization   = shipmentDisplay.ToOrganization;
            destination.ToName           = shipmentDisplay.ToName;
            destination.ToAddress1       = shipmentDisplay.ToAddress1;
            destination.ToAddress2       = shipmentDisplay.ToAddress2;
            destination.ToLocality       = shipmentDisplay.ToLocality;
            destination.ToRegion         = shipmentDisplay.ToRegion;
            destination.ToPostalCode     = shipmentDisplay.ToPostalCode;
            destination.ToCountryCode    = shipmentDisplay.ToCountryCode;
            destination.ToIsCommercial   = shipmentDisplay.ToIsCommercial;
            destination.Phone            = shipmentDisplay.Phone;
            destination.Email            = shipmentDisplay.Email;
            destination.ShipMethodKey    = shipmentDisplay.ShipMethodKey;
            destination.VersionKey       = shipmentDisplay.VersionKey;
            destination.Carrier          = shipmentDisplay.Carrier;
            destination.TrackingCode     = shipmentDisplay.TrackingCode;
            destination.TrackingUrl      = shipmentDisplay.TrackingUrl;
            destination.ShipmentStatus   = shipmentDisplay.ShipmentStatus.ToShipmentStatus();

            var existing = shipmentDisplay.Items.Where(x => x.Key != Guid.Empty);
            var removed  = destination.Items.Where(x => x.Key != Guid.Empty && existing.All(y => y.Key != x.Key)).ToArray();

            if (removed.Any())
            {
                foreach (var remover in removed)
                {
                    destination.Items.Remove(remover);
                }
            }

            return(destination);
        }
        public ShipmentDisplay PutShipment(ShipmentDisplay shipment)
        {
            var merchShipment = _shipmentService.GetByKey(shipment.Key);
            var orderKeys = shipment.Items.Select(x => x.ContainerKey).Distinct();

            if (merchShipment == null) throw new NullReferenceException("Shipment not found for key");

            merchShipment = shipment.ToShipment(merchShipment);

            _shipmentService.Save(merchShipment);

            this.UpdateOrderStatus(orderKeys);

            return merchShipment.ToShipmentDisplay();
        }
        public HttpResponseMessage UpdateShippingAddressLineItem(ShipmentDisplay shipment)
        {
            var merchShipment = _shipmentService.GetByKey(shipment.Key);

            // get the order keys from the shipment.  In general this will be a single
            // order but it is possible for this to be an enumeration
            var orderKeys = shipment.Items.Select(x => x.ContainerKey).Distinct();
            var orders = _orderService.GetByKeys(orderKeys);

            // get the collection of invoices assoicated with the orders.
            // again, this is typically only one.
            var invoiceKeys = orders.Select(x => x.InvoiceKey).Distinct();
            var invoices = _invoiceService.GetByKeys(invoiceKeys);

            foreach (var invoice in invoices)
            {
                // now we're going to update every shipment line item with the destination address
                var shippingLineItems = invoice.ShippingLineItems().ToArray();
                foreach (var lineItem in shippingLineItems)
                {
                    lineItem.ExtendedData.AddAddress(merchShipment.GetDestinationAddress(), Constants.ExtendedDataKeys.ShippingDestinationAddress);
                }
                _invoiceService.Save(invoice);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        public HttpResponseMessage PutShipment(ShipmentDisplay shipment)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var merchShipment = _shipmentService.GetByKey(shipment.Key);

                if (merchShipment == null)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                merchShipment = shipment.ToShipment(merchShipment);

                _shipmentService.Save(merchShipment);

            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", ex.Message));
            }

            return response;
        }