Beispiel #1
0
        public AmazonOrdersList GetAllAmazonOrdersData(DateTime submittedDate, IDatabaseCustomerMarketPlace databaseCustomerMarketPlace)
        {
            MP_CustomerMarketPlace customerMarketPlace = GetCustomerMarketPlace(databaseCustomerMarketPlace.Id);

            var orders = new AmazonOrdersList(submittedDate);

            orders.AddRange(customerMarketPlace
                            .AmazonOrders
                            .SelectMany(amazonOrder => amazonOrder.OrderItems)
                            .Distinct(new AmazonOrderComparer())
                            .Select(o => {
                AmazonOrdersList2ItemStatusType orderStatus;
                Enum.TryParse(o.OrderStatus, out orderStatus);
                return(new AmazonOrderItem {
                    OrderId = o.OrderId,
                    OrderStatus = orderStatus,
                    PurchaseDate = o.PurchaseDate,
                    LastUpdateDate = o.LastUpdateDate,
                    NumberOfItemsShipped = o.NumberOfItemsShipped,
                    NumberOfItemsUnshipped = o.NumberOfItemsUnshipped,
                    OrderTotal = _CurrencyConvertor.ConvertToBaseCurrency(o.OrderTotal, o.PurchaseDate),
                    PaymentsInfo =
                        new AmazonOrderItem2PaymentsInfoList(
                            o.PaymentsInfo.Select(pi => new AmazonOrderItem2PaymentInfoListItem {
                        MoneyInfo = _CurrencyConvertor.ConvertToBaseCurrency(pi.MoneyInfo, o.PurchaseDate),
                        PaymentMethod = pi.SubPaymentMethod
                    })),
                    SellerOrderId = o.SellerOrderId,
                });
            }));

            return(orders);
        }
Beispiel #2
0
        // AddAnalysisValues

        private IEnumerable <AmazonOrderItem> AnalyseOrder(AmazonOrdersList orders, int maxNumberOfItems = 10)
        {
            if (orders == null)
            {
                return(null);
            }

            var shippedOrders = orders.Where(o => o.OrderStatus == AmazonOrdersList2ItemStatusType.Shipped).ToList();

            if (shippedOrders.Count() <= maxNumberOfItems)
            {
                return(orders);
            }

            var rez =
                shippedOrders.GroupBy(x => new { x.OrderTotal.Value, x.OrderTotal.CurrencyCode, x.NumberOfItemsShipped },
                                      (key, group) =>
                                      new {
                Price = key.Value,
                key.CurrencyCode,
                key.NumberOfItemsShipped,
                Counter = group.Count()
            }).OrderByDescending(x => x.Counter).Take(maxNumberOfItems);

            return(rez.Select(x => shippedOrders.First(oi => oi.OrderTotal.Value == x.Price &&
                                                       oi.NumberOfItemsShipped == x.NumberOfItemsShipped &&
                                                       oi.OrderTotal.CurrencyCode == x.CurrencyCode)).ToList());
        }
Beispiel #3
0
        private AmazonOrderItemDetailsList GetOrderItems(
            AmazonSecurityInfo securityInfo,
            ActionAccessType access,
            AmazonOrderItem orderItem2,
            ElapsedTimeInfo elapsedTimeInfo,
            AmazonOrdersList orders,
            int mpId
            )
        {
            var itemsRequestInfo = new AmazonOrdersItemsRequestInfo {
                MarketplaceId     = securityInfo.MarketplaceId,
                MerchantId        = securityInfo.MerchantId,
                OrderId           = orderItem2.OrderId,
                ErrorRetryingInfo = this.amazonSettings,
                MWSAuthToken      = securityInfo.MWSAuthToken
            };

            AmazonOrderItemDetailsList orderItems = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(
                elapsedTimeInfo,
                mpId,
                ElapsedDataMemberType
                .RetrieveDataFromExternalService,
                () => AmazonServiceHelper.GetListItemsOrdered(this.connectionInfo, itemsRequestInfo, access, orders.RequestsCounter)
                );

            return(orderItems);
        }
        private void ParseOrdersStream(AmazonOrdersList orders, MemoryStream stream)
        {
            using (var sr = new StreamReader(stream)) {
                // заголовок
                var h = sr.ReadLine();

                while (sr.Peek() >= 0)
                {
                    var item = new AmazonOrderItem();
                    var str  = sr.ReadLine();
                    var list = str.Split(new[] { '\t' });

                    item.OrderId              = GetData(list, AmazonOrderDataEnum.OrderId);
                    item.LastUpdateDate       = ConvertToDate(GetData(list, AmazonOrderDataEnum.PaymentsDate));
                    item.PurchaseDate         = ConvertToDate(GetData(list, AmazonOrderDataEnum.PurchaseDate));
                    item.NumberOfItemsShipped = ConvertToInt(GetData(list, AmazonOrderDataEnum.QuantityPurchased));

                    item.OrderTotal = new AmountInfo {
                        Value        = ConvertToDouble(GetData(list, AmazonOrderDataEnum.ItemPrice)),
                        CurrencyCode = GetData(list, AmazonOrderDataEnum.Currency)
                    };

                    item.OrderStatus = AmazonOrdersList2ItemStatusType.Shipped;

                    orders.Add(item);
                }
            }
        }
        private AmazonOrdersList ParseOrdersResult(string getFlatFileOrdersDataRequestStr, RequestsListInfo reportRequestList)
        {
            var requestInfo = reportRequestList.GetRequestByName(getFlatFileOrdersDataRequestStr);

            AmazonOrdersList data = new AmazonOrdersList(reportRequestList.StartDate.Value);

            if (requestInfo != null && requestInfo.IsDone)
            {
                var reportRequestInfo = requestInfo.ReportData;
                if (reportRequestInfo != null)
                {
                    data = new AmazonOrdersList(reportRequestInfo.SubmittedDate);

                    using (var stream = new MemoryStream()) {
                        GetReportData(requestInfo, stream);
                        ParseOrdersStream(data, stream);
                    }
                }
            }
            return(data);
        }