示例#1
0
        public async Task <List <ProductDetailData> > ProductDetail(string templateID, ListArgs <ReportAdHocFilters> args, DecodedToken decodedToken)
        {
            IList <ListFilter> filters = await BuildFilters(templateID, args, decodedToken, "DateSubmitted", "SupplierID", statusPath : "Status");

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

            IQueryable <ProductDetailData> queryable = _productDetailRepository.GetQueryable()
                                                       .Where(order =>
                                                              order.PartitionKey == "PartitionValue");

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

            CosmosListPage <ProductDetailData> productDetailDataResponse = await _productDetailRepository.GetItemsAsync(queryable, requestOptions, listOptions);

            List <ProductDetailData> productDetailDataList = productDetailDataResponse.Items;

            listOptions.ContinuationToken = productDetailDataResponse.Meta.ContinuationToken;

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

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

            var productDetailList = new List <ProductDetailData>();

            var supplierFilter = args.Filters.FirstOrDefault(filter => filter.PropertyName == "SupplierID");

            var me = await _oc.Me.GetAsync(decodedToken.AccessToken);

            foreach (ProductDetailData detailData in productDetailDataList)
            {
                if (supplierFilter == null || supplierFilter.FilterExpression == detailData.Data.SupplierID)
                {
                    if (decodedToken.CommerceRole == CommerceRole.Seller || me.Supplier.ID == detailData.Data.SupplierID)
                    {
                        productDetailList.Add(detailData);
                    }
                }
            }

            return(productDetailList);
        }
示例#2
0
        private async Task ProcessProductAsync(Product product)
        {
            CosmosListPage <LineItemDetailData> lineItemData = await GetLineItemDataAsync(product.ID);

            List <ProductDetailData> productDataList = await CreateProductDetailDataAsync(product, lineItemData?.Items);

            //Get current products in Cosmos to update/replace
            var requestOptions = BuildQueryRequestOptions();

            foreach (ProductDetailData productData in productDataList)
            {
                var queryable = _productDetailRepo.GetQueryable().Where(x => x.PartitionKey == "PartitionValue" && x.Data.SpecCombo == productData.Data.SpecCombo);

                var listOptions = BuildProductListOptions(productData.ProductID, productData.Data.SpecCombo);

                CosmosListPage <ProductDetailData> currentProductDetailListPage = await _productDetailRepo.GetItemsAsync(queryable, requestOptions, listOptions);

                var cosmosID = "";
                if (currentProductDetailListPage.Items.Count == 1)
                {
                    cosmosID = productData.id = currentProductDetailListPage.Items[0].id;
                }

                await _productDetailRepo.UpsertItemAsync(cosmosID, productData);
            }
        }