private List <string> GetIdsToDelete(webModel.SearchCriteria searchCriteria)
        {
            // Any pagination for deleting should be managed at back-end.
            searchCriteria.Take = DeleteBatchSize;
            searchCriteria.Skip = 0;

            var  itemIds = new List <string>();
            bool hasItems;

            do
            {
                var searchResult   = SearchListEntries(searchCriteria);
                var listEntriesIds = searchResult.ListEntries
                                     .Where(x => x.Type.EqualsInvariant(KnownDocumentTypes.Product) || x.Type.EqualsInvariant(KnownDocumentTypes.Category))
                                     .Select(x => x.Id)
                                     .ToArray();

                hasItems = !listEntriesIds.IsNullOrEmpty();

                if (hasItems)
                {
                    itemIds.AddRange(listEntriesIds);
                    searchCriteria.Skip += searchCriteria.Take;
                }
            }while (hasItems);

            return(itemIds);
        }
示例#2
0
        public IHttpActionResult Search(SearchCriteria criteria)
        {
            var coreModelCriteria = criteria.ToCoreModel();

            ApplyRestrictionsForCurrentUser(coreModelCriteria);
            var serviceResult = _searchService.Search(coreModelCriteria);

            return(Ok(serviceResult.ToWebModel(_blobUrlResolver)));
        }
示例#3
0
        public IHttpActionResult ListItemsSearch(webModel.SearchCriteria criteria)
        {
            var coreModelCriteria = criteria.ToCoreModel();

            ApplyRestrictionsForCurrentUser(coreModelCriteria);

            coreModelCriteria.WithHidden = true;
            //Need search in children categories if user specify keyword
            if (!string.IsNullOrEmpty(coreModelCriteria.Keyword))
            {
                coreModelCriteria.SearchInChildren   = true;
                coreModelCriteria.SearchInVariations = true;
            }

            var retVal = new webModel.ListEntrySearchResult();

            int categorySkip = 0;
            int categoryTake = 0;

            //Because products and categories represent in search result as two separated collections for handle paging request
            //we should join two resulting collection artificially
            //search categories
            if ((coreModelCriteria.ResponseGroup & coreModel.SearchResponseGroup.WithCategories) == coreModel.SearchResponseGroup.WithCategories)
            {
                coreModelCriteria.ResponseGroup = coreModelCriteria.ResponseGroup & ~coreModel.SearchResponseGroup.WithProducts;
                var categoriesSearchResult = _searchService.Search(coreModelCriteria);
                var categoriesTotalCount   = categoriesSearchResult.Categories.Count();

                categorySkip = Math.Min(categoriesTotalCount, coreModelCriteria.Skip);
                categoryTake = Math.Min(coreModelCriteria.Take, Math.Max(0, categoriesTotalCount - coreModelCriteria.Skip));
                var categories = categoriesSearchResult.Categories.Skip(categorySkip).Take(categoryTake).Select(x => new webModel.ListEntryCategory(x.ToWebModel(_blobUrlResolver))).ToList();

                retVal.TotalCount = categoriesTotalCount;
                retVal.ListEntries.AddRange(categories);

                coreModelCriteria.ResponseGroup = coreModelCriteria.ResponseGroup | coreModel.SearchResponseGroup.WithProducts;
            }

            //search products
            if ((coreModelCriteria.ResponseGroup & coreModel.SearchResponseGroup.WithProducts) == coreModel.SearchResponseGroup.WithProducts)
            {
                coreModelCriteria.ResponseGroup = coreModelCriteria.ResponseGroup & ~coreModel.SearchResponseGroup.WithCategories;
                coreModelCriteria.Skip          = coreModelCriteria.Skip - categorySkip;
                coreModelCriteria.Take          = coreModelCriteria.Take - categoryTake;
                var productsSearchResult = _searchService.Search(coreModelCriteria);

                var products = productsSearchResult.Products.Select(x => new webModel.ListEntryProduct(x.ToWebModel(_blobUrlResolver)));

                retVal.TotalCount += productsSearchResult.ProductsTotalCount;
                retVal.ListEntries.AddRange(products);
            }


            return(Ok(retVal));
        }
        private webModel.ListEntrySearchResult SearchListEntries(webModel.SearchCriteria criteria)
        {
            var coreModelCriteria = criteria.ToCoreModel();

            ApplyRestrictionsForCurrentUser(coreModelCriteria);

            coreModelCriteria.WithHidden = true;

            // need search in children categories if user specify keyword
            if (!string.IsNullOrEmpty(coreModelCriteria.Keyword))
            {
                coreModelCriteria.SearchInChildren   = true;
                coreModelCriteria.SearchInVariations = true;
            }

            return(_listEntrySearchService.Search(coreModelCriteria));
        }
        public IHttpActionResult ListItemsSearch(webModel.SearchCriteria criteria)
        {
            var coreModelCriteria = criteria.ToCoreModel();

            ApplyRestrictionsForCurrentUser(coreModelCriteria);

            coreModelCriteria.WithHidden = true;

            // need search in children categories if user specify keyword
            if (!string.IsNullOrEmpty(coreModelCriteria.Keyword))
            {
                coreModelCriteria.SearchInChildren   = true;
                coreModelCriteria.SearchInVariations = true;
            }

            var result = _listEntrySearchService.Search(coreModelCriteria);

            return(Ok(result));
        }
        public static coreModel.SearchCriteria ToCoreModel(this webModel.SearchCriteria criteria)
        {
            var retVal = new coreModel.SearchCriteria();

            retVal.InjectFrom(criteria);

            retVal.ResponseGroup = criteria.ResponseGroup;
            retVal.CategoryIds   = criteria.CategoryIds;
            retVal.CatalogIds    = criteria.CatalogIds;
            retVal.PricelistIds  = criteria.PricelistIds;
            retVal.Terms         = criteria.Terms;
            retVal.Facets        = criteria.Facets;
            retVal.ProductTypes  = criteria.ProductTypes;
            retVal.VendorIds     = criteria.VendorIds;

            if (!criteria.PropertyValues.IsNullOrEmpty())
            {
                retVal.PropertyValues = criteria.PropertyValues.Select(x => x.ToCoreModel()).ToArray();
            }

            return(retVal);
        }
        public IHttpActionResult Delete(webModel.SearchCriteria searchCriteria)
        {
            var idsToDelete = searchCriteria.ObjectIds?.ToList() ?? new List <string>();
            var productIds  = new List <string>();
            var categoryIds = new List <string>();

            if (idsToDelete.IsNullOrEmpty())
            {
                idsToDelete = GetIdsToDelete(searchCriteria);
            }

            if (!idsToDelete.IsNullOrEmpty())
            {
                idsToDelete.ProcessWithPaging(DeleteBatchSize, (ids, currentItem, totalCount) =>
                {
                    var commonIds           = ids.ToArray();
                    var searchProductResult = _itemService.GetByIds(commonIds, coreModel.ItemResponseGroup.None);
                    CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Delete, searchProductResult);
                    productIds.AddRange(searchProductResult.Select(x => x.Id));

                    var searchCategoryResult = _categoryService.GetByIds(commonIds.ToArray(), coreModel.CategoryResponseGroup.None);
                    CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Delete, searchCategoryResult);
                    categoryIds.AddRange(searchCategoryResult.Select(x => x.Id));
                });

                productIds.ProcessWithPaging(DeleteBatchSize, (ids, currentItem, totalCount) =>
                {
                    _itemService.Delete(ids.ToArray());
                });

                categoryIds.ProcessWithPaging(DeleteBatchSize, (ids, currentItem, totalCount) =>
                {
                    _categoryService.Delete(ids.ToArray());
                });
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult ListItemsSearch(webModel.SearchCriteria criteria)
        {
            var result = SearchListEntries(criteria);

            return(Ok(result));
        }