コード例 #1
0
        public async Task <SuperHSShipment> Create([FromBody] SuperHSShipment superShipment)
        {
            // ocAuth is the token for the organization that is specified in the AppSettings

            // todo add auth to make sure suppliers are creating shipments for their own orders
            return(await _command.CreateShipment(superShipment, UserContext));
        }
コード例 #2
0
        public async Task <SuperHSShipment> CreateShipment(SuperHSShipment superShipment, string supplierToken)
        {
            ShipmentItem firstShipmentItem = superShipment.ShipmentItems.First();
            string       supplierOrderID   = firstShipmentItem.OrderID;
            string       buyerOrderID      = supplierOrderID.Split("-").First();

            // in the platform, in order to make sure the order has the proper Order.Status, you must
            // create a shipment without a DateShipped and then patch the DateShipped after
            DateTimeOffset?dateShipped = superShipment.Shipment.DateShipped;

            superShipment.Shipment.DateShipped = null;


            await PatchLineItemStatuses(supplierOrderID, superShipment);

            string buyerID = await GetBuyerIDForSupplierOrder(firstShipmentItem.OrderID);

            superShipment.Shipment.BuyerID = buyerID;

            HSShipment ocShipment = await _oc.Shipments.CreateAsync <HSShipment>(superShipment.Shipment, accessToken : supplierToken);

            //  platform issue. Cant save new xp values onto shipment line item. Update order line item to have this value.
            var shipmentItemsWithComment = superShipment.ShipmentItems.Where(s => s.xp?.Comment != null);
            await Throttler.RunAsync(shipmentItemsWithComment, 100, 5, (shipmentItem) =>
            {
                dynamic comments                  = new ExpandoObject();
                var commentsByShipment            = comments as IDictionary <string, object>;
                commentsByShipment[ocShipment.ID] = shipmentItem.xp?.Comment;
                return(_oc.LineItems.PatchAsync(OrderDirection.Incoming, buyerOrderID, shipmentItem.LineItemID,
                                                new PartialLineItem()
                {
                    xp = new
                    {
                        Comments = commentsByShipment
                    }
                }));
            });

            IList <ShipmentItem> shipmentItemResponses = await Throttler.RunAsync(
                superShipment.ShipmentItems,
                100,
                5,
                (shipmentItem) => _oc.Shipments.SaveItemAsync(ocShipment.ID, shipmentItem, accessToken: supplierToken));

            HSShipment ocShipmentWithDateShipped = await _oc.Shipments.PatchAsync <HSShipment>(ocShipment.ID, new PartialShipment()
            {
                DateShipped = dateShipped
            }, accessToken : supplierToken);

            return(new SuperHSShipment()
            {
                Shipment = ocShipmentWithDateShipped,
                ShipmentItems = shipmentItemResponses.ToList()
            });
        }
コード例 #3
0
ファイル: ShipmentCommand.cs プロジェクト: mmoebeck/headstart
        private async Task PatchLineItemStatuses(string supplierOrderID, SuperHSShipment superShipment, OrderDirection direction, DecodedToken decodedToken)
        {
            List <LineItemStatusChange> lineItemStatusChanges = superShipment.ShipmentItems.Select(shipmentItem =>
            {
                return(new LineItemStatusChange()
                {
                    Quantity = shipmentItem.QuantityShipped,
                    ID = shipmentItem.LineItemID
                });
            }).ToList();

            LineItemStatusChanges lineItemStatusChange = new LineItemStatusChanges()
            {
                Changes       = lineItemStatusChanges,
                Status        = LineItemStatus.Complete,
                SuperShipment = superShipment
            };
            await _lineItemCommand.UpdateLineItemStatusesAndNotifyIfApplicable(IsSupplierUser(decodedToken)?OrderDirection.Outgoing : direction, supplierOrderID, lineItemStatusChange);
        }
コード例 #4
0
        private async Task PatchLineItemStatuses(string supplierOrderID, SuperHSShipment superShipment, OrderDirection direction, VerifiedUserContext userContext)
        {
            List <LineItemStatusChange> lineItemStatusChanges = superShipment.ShipmentItems.Select(shipmentItem =>
            {
                return(new LineItemStatusChange()
                {
                    Quantity = shipmentItem.QuantityShipped,
                    ID = shipmentItem.LineItemID
                });
            }).ToList();

            LineItemStatusChanges lineItemStatusChange = new LineItemStatusChanges()
            {
                Changes       = lineItemStatusChanges,
                Status        = LineItemStatus.Complete,
                SuperShipment = superShipment
            };

            await _lineItemCommand.UpdateLineItemStatusesAndNotifyIfApplicable(direction, supplierOrderID, lineItemStatusChange, userContext);
        }