public coreModel.Category[] GetByIds(string[] categoryIds, coreModel.CategoryResponseGroup responseGroup, string catalogId = null)
        {
            coreModel.Category[] result;

            using (var repository = _catalogRepositoryFactory())
            {
                result = repository.GetCategoriesByIds(categoryIds, responseGroup)
                         .Select(c => c.ToCoreModel())
                         .ToArray();
            }

            // Fill outlines for products
            if (responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithOutlines))
            {
                _outlineService.FillOutlinesForObjects(result, catalogId);
            }

            // Fill SEO info
            if ((responseGroup & coreModel.CategoryResponseGroup.WithSeo) == coreModel.CategoryResponseGroup.WithSeo)
            {
                var objectsWithSeo = new List <ISeoSupport>(result);

                var outlineItems = result
                                   .Where(c => c.Outlines != null)
                                   .SelectMany(c => c.Outlines.SelectMany(o => o.Items));
                objectsWithSeo.AddRange(outlineItems);

                _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray());
            }

            return(result);
        }
        public dataModel.Category[] GetCategoriesByIds(string[] categoriesIds, coreModel.CategoryResponseGroup respGroup)
        {
            if (categoriesIds == null)
            {
                throw new ArgumentNullException("categoriesIds");
            }

            if (!categoriesIds.Any())
            {
                return(new dataModel.Category[] { });
            }

            var result = Categories.Include(x => x.Catalog.CatalogLanguages)
                         .Where(x => categoriesIds.Contains(x.Id)).ToArray();

            if ((respGroup & coreModel.CategoryResponseGroup.WithLinks) == coreModel.CategoryResponseGroup.WithLinks)
            {
                var incommingLinks = CategoryLinks.Where(x => categoriesIds.Contains(x.TargetCategoryId)).ToArray();
                var outgoingLinks  = CategoryLinks.Where(x => categoriesIds.Contains(x.SourceCategoryId)).ToArray();
            }

            if ((respGroup & coreModel.CategoryResponseGroup.WithImages) == coreModel.CategoryResponseGroup.WithImages)
            {
                var images = Images.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();
            }

            if (((respGroup & coreModel.CategoryResponseGroup.WithParents) == coreModel.CategoryResponseGroup.WithParents) ||
                ((respGroup & coreModel.CategoryResponseGroup.WithProperties) == coreModel.CategoryResponseGroup.WithProperties))
            {
                var parentsMap = GetAllCategoriesParents(categoriesIds);
                foreach (var categoryId in categoriesIds)
                {
                    var category = result.FirstOrDefault(x => x.Id == categoryId);
                    if (category != null)
                    {
                        category.AllParents = parentsMap[categoryId];
                    }
                }
            }

            if ((respGroup & coreModel.CategoryResponseGroup.WithProperties) == coreModel.CategoryResponseGroup.WithProperties)
            {
                //Load property values by separate query
                var propertyValues = PropertyValues.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();
                //Need load inherited from parents categories and catalogs
                var allParents           = result.SelectMany(x => x.AllParents).ToArray();
                var allCategoriesTreeIds = allParents.Select(x => x.Id).Concat(categoriesIds).Distinct().ToArray();
                var allCatalogsIds       = result.Select(x => x.CatalogId).Concat(allParents.Select(x => x.CatalogId)).Distinct().ToArray();

                var categoriesProperties = Properties.Include(x => x.PropertyAttributes)
                                           .Include(x => x.DictionaryValues)
                                           .Where(x => allCategoriesTreeIds.Contains(x.CategoryId)).ToArray();

                var catalogProperties = Properties.Include(x => x.PropertyAttributes)
                                        .Include(x => x.DictionaryValues)
                                        .Where(x => x.CategoryId == null && allCatalogsIds.Contains(x.CatalogId)).ToArray();
            }
            return(result);
        }
        public IHttpActionResult GetCategoriesByIds([FromUri] string[] ids, [FromUri] coreModel.CategoryResponseGroup respGroup = coreModel.CategoryResponseGroup.Full)
        {
            var categories = _categoryService.GetByIds(ids, respGroup);

            CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Read, categories);

            var retVal = categories.Select(x => x.ToWebModel(_blobUrlResolver)).ToArray();

            foreach (var category in retVal)
            {
                category.SecurityScopes = GetObjectPermissionScopeStrings(category);
            }

            return(Ok(retVal));
        }
Beispiel #4
0
        public coreModel.Category[] GetByIds(string[] categoryIds, coreModel.CategoryResponseGroup responseGroup)
        {
            var retVal = new List <coreModel.Category>();

            using (var repository = _catalogRepositoryFactory())
            {
                var categories = repository.GetCategoriesByIds(categoryIds, responseGroup).Select(x => x.ToCoreModel()).ToArray();
                retVal.AddRange(categories);
                if ((responseGroup & coreModel.CategoryResponseGroup.WithSeo) == coreModel.CategoryResponseGroup.WithSeo)
                {
                    _commerceService.LoadSeoForObjects(categories);
                }
            }

            return(retVal.ToArray());
        }
        public dataModel.Category[] GetCategoriesByIds(string[] categoriesIds, coreModel.CategoryResponseGroup respGroup)
        {
            if (categoriesIds == null)
            {
                throw new ArgumentNullException("categoriesIds");
            }

            if (!categoriesIds.Any())
            {
                return(new dataModel.Category[] { });
            }

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithOutlines))
            {
                respGroup |= coreModel.CategoryResponseGroup.WithLinks | coreModel.CategoryResponseGroup.WithParents;
            }

            var result = Categories.Where(x => categoriesIds.Contains(x.Id)).ToArray();

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithLinks))
            {
                var incommingLinks = CategoryLinks.Where(x => categoriesIds.Contains(x.TargetCategoryId)).ToArray();
                var outgoingLinks  = CategoryLinks.Where(x => categoriesIds.Contains(x.SourceCategoryId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithImages))
            {
                var images = Images.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();
            }

            //Load category property values by separate query
            var propertyValues = PropertyValues.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();

            //Load all properties meta information and information for inheritance
            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithProperties))
            {
                var categoriesProperties = Properties.Include(x => x.PropertyAttributes)
                                           .Include(x => x.DictionaryValues)
                                           .Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();
            }

            return(result);
        }
        public virtual coreModel.Category[] GetByIds(string[] categoryIds, coreModel.CategoryResponseGroup responseGroup, string catalogId = null)
        {
            coreModel.Category[] result;

            using (var repository = base.CatalogRepositoryFactory())
            {
                result = repository.GetCategoriesByIds(categoryIds, responseGroup)
                         .Select(c => c.ToCoreModel(base.AllCachedCatalogs, base.AllCachedCategories))
                         .ToArray();
            }

            // Fill outlines for products
            if (responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithOutlines))
            {
                _outlineService.FillOutlinesForObjects(result, catalogId);
            }

            if ((responseGroup & coreModel.CategoryResponseGroup.WithSeo) == coreModel.CategoryResponseGroup.WithSeo)
            {
                var objectsWithSeo = new List <ISeoSupport>(result);

                var outlineItems = result
                                   .Where(c => c.Outlines != null)
                                   .SelectMany(c => c.Outlines.SelectMany(o => o.Items));
                objectsWithSeo.AddRange(outlineItems);

                _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray());
            }

            //Cleanup result model considered requested response group
            foreach (var category in result)
            {
                if (!responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithParents))
                {
                    category.Parents = null;
                }
                if (!responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithProperties))
                {
                    category.Properties = null;
                }
            }
            return(result);
        }
        public dataModel.CategoryEntity[] GetCategoriesByIds(string[] categoriesIds, coreModel.CategoryResponseGroup respGroup)
        {
            var result = Array.Empty <dataModel.CategoryEntity>();

            if (!categoriesIds.IsNullOrEmpty())
            {
                if (respGroup.HasFlag(CategoryResponseGroup.WithOutlines))
                {
                    respGroup |= CategoryResponseGroup.WithLinks | CategoryResponseGroup.WithParents;
                }

                result = Categories.Where(x => categoriesIds.Contains(x.Id)).ToArray();

                if (result.Any())
                {
                    categoriesIds = result.Select(x => x.Id).ToArray();

                    if (respGroup.HasFlag(CategoryResponseGroup.WithLinks))
                    {
                        var incommingLinks = CategoryLinks.Where(x => categoriesIds.Contains(x.TargetCategoryId)).ToArray();
                        var outgoingLinks  = CategoryLinks.Where(x => categoriesIds.Contains(x.SourceCategoryId)).ToArray();
                    }

                    if (respGroup.HasFlag(CategoryResponseGroup.WithImages))
                    {
                        var images = Images.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();
                    }

                    //Load all properties meta information and information for inheritance
                    if (respGroup.HasFlag(CategoryResponseGroup.WithProperties))
                    {
                        //Load category property values by separate query
                        var propertyValues = PropertyValues.Include(x => x.DictionaryItem.DictionaryItemValues).Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();

                        var categoryPropertiesIds = Properties.Where(x => categoriesIds.Contains(x.CategoryId)).Select(x => x.Id).ToArray();
                        var categoryProperties    = GetPropertiesByIds(categoryPropertiesIds);
                    }
                }
            }

            return(result);
        }
 public coreModel.Category GetById(string categoryId, coreModel.CategoryResponseGroup responseGroup, string catalogId = null)
 {
     return(GetByIds(new[] { categoryId }, responseGroup, catalogId).FirstOrDefault());
 }
 public IHttpActionResult GetCategoriesByPlentyIds([FromBody] string[] ids, [FromUri] coreModel.CategoryResponseGroup respGroup = coreModel.CategoryResponseGroup.Full)
 {
     return(GetCategoriesByIds(ids, respGroup));
 }
Beispiel #10
0
        private IDictionary <string, dataModel.Category[]> GetAllCategoriesParents(string[] categoryIds, coreModel.CategoryResponseGroup respGroup)
        {
            const string queryPattern =
                @"WITH items AS ( SELECT Id, Name,  0 AS Level, CAST(Id AS VARCHAR(255)) AS Path
                  FROM Category WHERE ParentCategoryId IS NULL
                  UNION ALL
                  SELECT i.Id, i.Name, Level + 1, CAST(Path + '|' + CAST(i.Id AS VARCHAR(255)) AS VARCHAR(255)) AS Path
                  FROM Category i
                  INNER JOIN items itms ON itms.Id = i.ParentCategoryId)
                  SELECT * FROM items WHERE Id IN ({0}) ORDER BY Path";

            var query = string.Format(queryPattern, string.Join(", ", categoryIds.Select(x => string.Format("'{0}'", x))));

            var outlines            = ObjectContext.ExecuteStoreQuery <CategoryOutline>(query).ToArray();
            var parentCategoriesIds = outlines.SelectMany(x => x.Path.Split('|')).Distinct().ToArray();
            var allParentCategories = GetCategoriesByIds(parentCategoriesIds, respGroup);

            var retVal = new Dictionary <string, dataModel.Category[]>();

            foreach (var categoryId in categoryIds)
            {
                var parents = new List <dataModel.Category>();
                var outline = outlines.FirstOrDefault(x => x.Id == categoryId);
                if (outline != null)
                {
                    foreach (var parentId in outline.Path.Split('|'))
                    {
                        if (parentId != categoryId)
                        {
                            parents.Add(allParentCategories.First(x => x.Id == parentId));
                        }
                    }
                }
                retVal[categoryId] = parents.ToArray();
            }
            return(retVal);
        }
Beispiel #11
0
        public dataModel.Category[] GetCategoriesByIds(string[] categoriesIds, coreModel.CategoryResponseGroup respGroup)
        {
            if (categoriesIds == null)
            {
                throw new ArgumentNullException("categoriesIds");
            }

            if (!categoriesIds.Any())
            {
                return(new dataModel.Category[] { });
            }

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithOutlines))
            {
                respGroup |= coreModel.CategoryResponseGroup.WithLinks | coreModel.CategoryResponseGroup.WithParents;
            }

            var result = Categories.Include(x => x.Catalog.CatalogLanguages)
                         .Where(x => categoriesIds.Contains(x.Id)).ToArray();

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithLinks))
            {
                var incommingLinks     = CategoryLinks.Where(x => categoriesIds.Contains(x.TargetCategoryId)).ToArray();
                var outgoingLinks      = CategoryLinks.Where(x => categoriesIds.Contains(x.SourceCategoryId)).ToArray();
                var foreignCatalogsIds = outgoingLinks.Where(x => x.TargetCategoryId == null && x.TargetCatalogId != null)
                                         .Select(x => x.TargetCatalogId).Distinct().ToArray();
                var foreginCategoriesIds = outgoingLinks.Where(x => x.TargetCategoryId != null)
                                           .Select(x => x.TargetCategoryId).Distinct();
                if (!foreginCategoriesIds.IsNullOrEmpty())
                {
                    var linkedCategories = GetCategoriesByIds(foreginCategoriesIds.ToArray(), coreModel.CategoryResponseGroup.WithLinks | coreModel.CategoryResponseGroup.WithParents);
                }
                if (!foreignCatalogsIds.IsNullOrEmpty())
                {
                    var linkedCatalogs = Catalogs.Include(x => x.CatalogLanguages).Where(x => foreignCatalogsIds.Contains(x.Id)).ToArray();
                }
            }

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithImages))
            {
                var images = Images.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithParents) || respGroup.HasFlag(coreModel.CategoryResponseGroup.WithProperties))
            {
                var parentsMap = GetAllCategoriesParents(categoriesIds, coreModel.CategoryResponseGroup.WithLinks);
                foreach (var categoryId in categoriesIds)
                {
                    var category = result.FirstOrDefault(x => x.Id == categoryId);
                    if (category != null)
                    {
                        category.AllParents = parentsMap[categoryId];
                        foreach (var parent in category.AllParents)
                        {
                            parent.AllParents = category.AllParents.TakeWhile(x => x != parent).ToArray();
                        }
                    }
                }
            }

            //Load category property values by separate query
            var propertyValues = PropertyValues.Where(x => categoriesIds.Contains(x.CategoryId)).ToArray();

            //Load all properties meta information and information for inheritance
            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithProperties))
            {
                //Need load inherited from parents categories and catalogs
                var allParents           = result.SelectMany(x => x.AllParents).ToArray();
                var allCategoriesTreeIds = allParents.Select(x => x.Id).Concat(categoriesIds).Distinct().ToArray();
                var allCatalogsIds       = result.Select(x => x.CatalogId).Concat(allParents.Select(x => x.CatalogId)).Distinct().ToArray();

                var categoriesProperties = Properties.Include(x => x.PropertyAttributes)
                                           .Include(x => x.DictionaryValues)
                                           .Where(x => allCategoriesTreeIds.Contains(x.CategoryId)).ToArray();

                var catalogProperties = Properties.Include(x => x.PropertyAttributes)
                                        .Include(x => x.DictionaryValues)
                                        .Where(x => x.CategoryId == null && allCatalogsIds.Contains(x.CatalogId)).ToArray();
            }

            return(result);
        }
        public webModel.Category[] GetCategoriesByIds([ModelBinder(typeof(IdsStringArrayBinder))] string[] ids, [FromUri] coreModel.CategoryResponseGroup respGroup = coreModel.CategoryResponseGroup.Full)
        {
            var categories = _categoryService.GetByIds(ids, respGroup);

            base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Read, categories);

            var retVal = categories.Select(x => x.ToWebModel(_blobUrlResolver));

            foreach (var category in retVal)
            {
                category.SecurityScopes = base.GetObjectPermissionScopeStrings(category);
            }

            return(retVal.ToArray());
        }