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[] { });
            }

            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 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.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();
            }

            if (respGroup.HasFlag(coreModel.CategoryResponseGroup.WithParents) || respGroup.HasFlag(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];
                    }
                }
            }

            //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);
        }