示例#1
0
        private void ExportPropertiesDictionaryItems(JsonTextWriter writer, JsonSerializer serializer, ExportImportProgressInfo progressInfo, Action <ExportImportProgressInfo> progressCallback)
        {
            progressInfo.Description = "The dictionary items are exporting…";
            progressCallback(progressInfo);

            var criteria = new PropertyDictionaryItemSearchCriteria {
                Take = 0, Skip = 0
            };
            var totalCount = _propertyDictionarySearchService.Search(criteria).TotalCount;

            writer.WritePropertyName("PropertyDictionaryItemsTotalCount");
            writer.WriteValue(totalCount);

            writer.WritePropertyName("PropertyDictionaryItems");
            writer.WriteStartArray();
            for (var i = 0; i < totalCount; i += BatchSize)
            {
                var searchResponse = _propertyDictionarySearchService.Search(new PropertyDictionaryItemSearchCriteria {
                    Take = BatchSize, Skip = i
                });
                foreach (var dictItem in searchResponse.Results)
                {
                    serializer.Serialize(writer, dictItem);
                }
                writer.Flush();
                progressInfo.Description = $"{ Math.Min(totalCount, i + BatchSize) } of { totalCount } dictionary items have been exported";
                progressCallback(progressInfo);
            }
            writer.WriteEndArray();
        }
示例#2
0
        public IHttpActionResult GetPropertyValues(string propertyId, [FromUri] string keyword = null)
        {
            var dictValues = _propertyDictionarySearchService.Search(new moduleModel.Search.PropertyDictionaryItemSearchCriteria {
                SearchPhrase = keyword, PropertyIds = new[] { propertyId }, Take = int.MaxValue
            }).Results;

            return(Ok(dictValues.Select(x => new webModel.PropertyDictionaryValue {
                Id = x.Id, Alias = x.Alias, ValueId = x.PropertyId, Value = x.Alias
            }).ToArray()));
        }
        public IHttpActionResult SearchPropertyDictionaryItems(PropertyDictionaryItemSearchCriteria criteria)
        {
            var result = _propertyDictionarySearchService.Search(criteria);
            var retVal = new webModel.PropertyDictionaryItemSearchResult
            {
                Results    = result.Results,
                TotalCount = result.TotalCount
            };

            return(Ok(retVal));
        }
        protected override ExportableSearchResult FetchData(PropertyDictionaryItemExportSearchCriteria searchCriteria)
        {
            var criteria = new PropertyDictionaryItemSearchCriteria {
                Take = searchCriteria.Take, Skip = searchCriteria.Skip, CatalogIds = searchCriteria.CatalogIds
            };
            var searchResponse = _propertyDictionarySearchService.Search(criteria);

            return(new ExportableSearchResult
            {
                TotalCount = searchResponse.TotalCount,
                Results = searchResponse.Results.Select(y => AbstractTypeFactory <ExportablePropertyDictionaryItem> .TryCreateInstance().FromModel(y)).Cast <IExportable>().ToList()
            });
        }
        protected virtual void AddLabels(IList <Aggregation> aggregations, string catalogId)
        {
            var allProperties = _propertyService.GetAllCatalogProperties(catalogId);

            foreach (var aggregation in aggregations)
            {
                // There can be many properties with the same name
                var properties = allProperties.Where(p => p.Name.EqualsInvariant(aggregation.Field)).ToArray();

                if (properties.Any())
                {
                    var allPropertyLabels = properties.SelectMany(p => p.DisplayNames)
                                            .Select(n => new AggregationLabel {
                        Language = n.LanguageCode, Label = n.Name
                    })
                                            .ToArray();

                    aggregation.Labels = GetFirstLabelForEachLanguage(allPropertyLabels);

                    var allDictItemsMap = _propDictItemsSearchService.Search(new PropertyDictionaryItemSearchCriteria {
                        PropertyIds = properties.Select(x => x.Id).ToArray(), Take = int.MaxValue
                    })
                                          .Results.GroupBy(x => x.Alias)
                                          .ToDictionary(x => x.Key, x => x.SelectMany(dictItem => dictItem.LocalizedValues)
                                                        .Select(localizedValue => new AggregationLabel {
                        Language = localizedValue.LanguageCode, Label = localizedValue.Value
                    }));

                    foreach (var aggregationItem in aggregation.Items)
                    {
                        var alias = aggregationItem.Value?.ToString();
                        if (!string.IsNullOrEmpty(alias))
                        {
                            if (allDictItemsMap.TryGetValue(alias, out var labels))
                            {
                                aggregationItem.Labels = GetFirstLabelForEachLanguage(labels);
                            }
                        }
                    }
                }
            }
        }
        public IHttpActionResult GetPropertyValues(string storeId, string propertyName)
        {
            var result = Array.Empty <string>();
            var store  = _storeService.GetById(storeId);

            if (store == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }

            CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.ReadBrowseFilters, store);

            var property = _propertyService.GetAllCatalogProperties(store.Catalog).Where(p => p.Name.EqualsInvariant(propertyName) && p.Dictionary).FirstOrDefault();

            if (property != null)
            {
                result = _propDictItemsSearchService.Search(new Domain.Catalog.Model.Search.PropertyDictionaryItemSearchCriteria {
                    PropertyIds = new[] { property.Id }, Take = int.MaxValue
                }).Results.Select(x => x.Alias).Distinct().ToArray();
            }
            return(Ok(result));
        }
        private void ResolvePropertyDictionaryItems(List <CsvProduct> csvProducts, ExportImportProgressInfo progressInfo, Action <ExportImportProgressInfo> progressCallback)
        {
            var allDictPropertyIds = csvProducts.SelectMany(x => x.Properties).Where(x => x.Dictionary)
                                     .Select(x => x.Id).Distinct()
                                     .ToArray();

            var allDictItems = _propDictItemSearchService.Search(new PropertyDictionaryItemSearchCriteria
            {
                PropertyIds = allDictPropertyIds,
                Take        = int.MaxValue
            }).Results;

            foreach (var dictPropValue in csvProducts.SelectMany(x => x.PropertyValues).Where(x => x.Property != null && x.Property.Dictionary && !string.IsNullOrEmpty(x.Value?.ToString())))
            {
                dictPropValue.Alias = dictPropValue.Value.ToString();
                var existDictItem = allDictItems.FirstOrDefault(x => x.PropertyId == dictPropValue.Property.Id && x.Alias.EqualsInvariant(dictPropValue.Alias));
                if (existDictItem == null)
                {
                    if (_createPropertyDictionatyValues)
                    {
                        existDictItem = new PropertyDictionaryItem
                        {
                            Alias      = dictPropValue.Alias,
                            PropertyId = dictPropValue.Property.Id
                        };
                        allDictItems.Add(existDictItem);
                        _propDictItemService.SaveChanges(new[] { existDictItem });
                    }
                    else
                    {
                        progressInfo.Errors.Add($"The property dictionary '{dictPropValue.Alias}' not found in '{dictPropValue.Property.Name}' dictionary");
                        progressCallback(progressInfo);
                    }
                }
                dictPropValue.ValueId = existDictItem?.Id;
            }
        }
示例#8
0
        public IHttpActionResult SearchPropertyDictionaryItems(PropertyDictionaryItemSearchCriteria criteria)
        {
            var result = _propertyDictionarySearchService.Search(criteria);

            return(Ok(result));
        }