Ejemplo n.º 1
0
        public async Task <List <HSLineItemOrder> > BuyerLineItemDetail(ListArgs <HSOrder> args, BuyerReportViewContext viewContext, string userID, string locationID, DecodedToken decodedToken)
        {
            IList <ListFilter> filters = new List <ListFilter>();

            filters.Add(ApplyBuyerLineContext(viewContext, userID, locationID, decodedToken));

            foreach (var filter in args.Filters)
            {
                filters.Add(ApplyBuyerLineFilter(filter));
            }

            CosmosListOptions listOptions = new CosmosListOptions()
            {
                PageSize      = -1,
                Sort          = "OrderID",
                SortDirection = SortDirection.ASC,
                Filters       = filters,
            };

            IQueryable <LineItemDetailData> queryable = _lineItemDetail.GetQueryable()
                                                        .Where(order =>
                                                               order.PartitionKey == "PartitionValue");

            QueryRequestOptions requestOptions = new QueryRequestOptions
            {
                MaxItemCount   = listOptions.PageSize,
                MaxConcurrency = -1
            };

            CosmosListPage <LineItemDetailData> lineItemDataResponse = await _lineItemDetail.GetItemsAsync(queryable, requestOptions, listOptions);

            List <LineItemDetailData> lineItemData = lineItemDataResponse.Items;

            listOptions.ContinuationToken = lineItemDataResponse.Meta.ContinuationToken;

            while (listOptions.ContinuationToken != null)
            {
                CosmosListPage <LineItemDetailData> responseWithToken = await _lineItemDetail.GetItemsAsync(queryable, requestOptions, listOptions);

                lineItemData.AddRange(responseWithToken.Items);
                listOptions.ContinuationToken = responseWithToken.Meta.ContinuationToken;
            }

            var lineItems = new List <HSLineItemOrder>();

            foreach (LineItemDetailData detailData in lineItemData)
            {
                foreach (HSLineItem lineDetail in detailData.Data.LineItems)
                {
                    lineItems.Add(new HSLineItemOrder
                    {
                        HSOrder    = detailData.Data.Order,
                        HSLineItem = lineDetail
                    });
                }
            }

            return(lineItems);
        }
Ejemplo n.º 2
0
        private async Task UpsertLineItemDetail(string orderID)
        {
            var orderWorksheet = await _oc.IntegrationEvents.GetWorksheetAsync <HSOrderWorksheet>(OrderDirection.Incoming, orderID);

            var lineItems = await _oc.LineItems.ListAllAsync <HSLineItem>(OrderDirection.Incoming, orderID);

            var buyer = await _oc.Buyers.GetAsync <HSBuyer>(orderWorksheet.Order.FromCompanyID);

            var lineItemsWithMiscFields = await BuildLineItemsMiscFields(lineItems, orderWorksheet, buyer.Name);

            var lineItemsWithPurchaseOrders = await BuildLineItemsWithPurchaseOrders(orderID);

            var orderLineItemData = new HSOrderLineItemData()
            {
                Order     = orderWorksheet.Order,
                LineItems = lineItems,
                LineItemsWithMiscFields          = lineItemsWithMiscFields,
                LineItemsWithPurchaseOrderFields = lineItemsWithPurchaseOrders
            };

            var queryable = _lineItemDetailDataRepo.GetQueryable().Where(order => order.PartitionKey == "PartitionValue");

            var requestOptions = BuildQueryRequestOptions();

            var cosmosLineItemOrder = new LineItemDetailData()
            {
                PartitionKey = "PartitionValue",
                OrderID      = orderID,
                Data         = orderLineItemData
            };

            var listOptions = BuildListOptions(orderID);

            CosmosListPage <LineItemDetailData> currentLineItemListPage = await _lineItemDetailDataRepo.GetItemsAsync(queryable, requestOptions, listOptions);

            var cosmosID = "";

            if (currentLineItemListPage.Items.Count() == 1)
            {
                cosmosID = cosmosLineItemOrder.id = currentLineItemListPage.Items[0].id;
            }

            await _lineItemDetailDataRepo.UpsertItemAsync(cosmosID, cosmosLineItemOrder);
        }
Ejemplo n.º 3
0
        private async Task <CosmosListPage <LineItemDetailData> > GetLineItemDataAsync(string productID)
        {
            var queryable = _lineItemDetailDataRepo
                            .GetQueryable()
                            .Where(order => order.Data.LineItems.Any(lineItem => lineItem.ProductID == productID) && order.Data.Order.DateCreated > DateTime.Now.AddMonths(-12));

            var requestOptions = new QueryRequestOptions()
            {
                MaxItemCount = 1
            };

            CosmosListOptions listOptions = new CosmosListOptions()
            {
                PageSize = 100, ContinuationToken = null
            };

            CosmosListPage <LineItemDetailData> currentLineItemListPage = await _lineItemDetailDataRepo.GetItemsAsync(queryable, requestOptions, listOptions);

            return(currentLineItemListPage);
        }