예제 #1
0
        public OrderType[] GeteBayOrdersByOrderLineItemID(IList <string> orderLineItemIDs)
        {
            try
            {
                if (orderLineItemIDs == null || orderLineItemIDs.Count == 0)
                {
                    return(default(OrderType[]));
                }

                GetOrderTransactionsCall        getOrderTransactionCall;
                GetOrderTransactionsRequestType getOrderTransactionRequest;

                DetailLevelCodeTypeCollection detailLevelColl = new DetailLevelCodeTypeCollection();
                detailLevelColl.Add(DetailLevelCodeType.ItemReturnDescription);

                var apiContext = _eBayApiContextProvider.GetAPIContext();

                List <OrderType> returnOrders = new List <OrderType>();

                getOrderTransactionCall                = new GetOrderTransactionsCall(apiContext);
                getOrderTransactionRequest             = new GetOrderTransactionsRequestType();
                getOrderTransactionRequest.DetailLevel = detailLevelColl;

                int pageSize   = 20;
                int totalPage  = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(orderLineItemIDs.Count()) / Convert.ToDecimal(pageSize)));
                int pageNumber = 1;

                do
                {
                    getOrderTransactionRequest.ItemTransactionIDArray = new ItemTransactionIDTypeCollection();
                    var lstTransactionIDs = orderLineItemIDs.Select(olid => new ItemTransactionIDType()
                    {
                        OrderLineItemID = olid
                    }).Skip((pageNumber - 1) * pageSize).Take(pageSize);
                    getOrderTransactionRequest.ItemTransactionIDArray.AddRange(lstTransactionIDs.ToArray());

                    var getOrderTransactionResponse = getOrderTransactionCall.ExecuteRequest(getOrderTransactionRequest) as GetOrderTransactionsResponseType;
                    if (getOrderTransactionResponse.OrderArray != null && getOrderTransactionResponse.OrderArray.Count > 0)
                    {
                        returnOrders.AddRange(getOrderTransactionResponse.OrderArray.ToArray());
                    }

                    pageNumber++;
                } while (pageNumber <= totalPage);

                return(returnOrders.ToArray());
            }
            catch (Exception ex)
            {
                LogManager.Instance.Error(ex.Message);
                throw ex;
            }
        }
예제 #2
0
        public OrderType[] GeteBayOrdersByOrderLineItemID(IList <OrderLineItemIDObject> orderLineItemIDs)
        {
            try
            {
                if (orderLineItemIDs == null || orderLineItemIDs.Count == 0)
                {
                    return(default(OrderType[]));
                }

                GetOrderTransactionsCall        getOrderTransactionCall;
                GetOrderTransactionsRequestType getOrderTransactionRequest;

                DetailLevelCodeTypeCollection detailLevelColl = new DetailLevelCodeTypeCollection();
                detailLevelColl.Add(DetailLevelCodeType.ReturnAll);

                var apiContexts = _eBayAPIContextProvider.GetAPIContext();

                List <OrderType> returnOrders = new List <OrderType>();


                var orderLineItemIDGroup = orderLineItemIDs.GroupBy(i => i.SellerID);
                foreach (var sellerGroupItemID in orderLineItemIDGroup)
                {
                    var apiContext = apiContexts.Where(c => c.ApiCredential.eBayAccount.UserName.ToLower().Equals(sellerGroupItemID.Key.ToLower())).FirstOrDefault();
                    if (apiContext != null)
                    {
                        getOrderTransactionCall                = new GetOrderTransactionsCall(apiContext);
                        getOrderTransactionRequest             = new GetOrderTransactionsRequestType();
                        getOrderTransactionRequest.DetailLevel = detailLevelColl;

                        int pageSize   = 20;
                        int totalPage  = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(sellerGroupItemID.Count()) / Convert.ToDecimal(pageSize)));
                        int pageNumber = 1;

                        do
                        {
                            getOrderTransactionRequest.ItemTransactionIDArray = new ItemTransactionIDTypeCollection();
                            var lstTransactionIDs = sellerGroupItemID.Select(gi => new ItemTransactionIDType()
                            {
                                OrderLineItemID = gi.OrderLineItemID
                            }).Skip((pageNumber - 1) * pageSize).Take(pageSize);
                            getOrderTransactionRequest.ItemTransactionIDArray.AddRange(lstTransactionIDs.ToArray());

                            var getOrderTransactionResponse = getOrderTransactionCall.ExecuteRequest(getOrderTransactionRequest) as GetOrderTransactionsResponseType;
                            if (getOrderTransactionResponse.OrderArray != null && getOrderTransactionResponse.OrderArray.Count > 0)
                            {
                                returnOrders.AddRange(getOrderTransactionResponse.OrderArray.ToArray());
                            }

                            pageNumber++;
                        } while (pageNumber <= totalPage);
                        //foreach (var orderLineItemIDObj in sellerGroupItemID)
                        //{

                        //}
                    }
                }


                return(returnOrders.ToArray());
            }
            catch (Exception ex)
            {
                return(default(OrderType[]));
            }
        }