public async Task <CategoryEntity[]> GetCategoriesByIdsAsync(string[] categoriesIds, CategoryResponseGroup respGroup) { var result = Array.Empty <CategoryEntity>(); if (!categoriesIds.IsNullOrEmpty()) { result = await Categories.Where(x => categoriesIds.Contains(x.Id)).ToArrayAsync(); if (result.Any()) { if (respGroup.HasFlag(CategoryResponseGroup.WithOutlines)) { respGroup |= CategoryResponseGroup.WithLinks | CategoryResponseGroup.WithParents; } if (respGroup.HasFlag(CategoryResponseGroup.WithLinks)) { var incommingLinksTask = CategoryLinks.Where(x => categoriesIds.Contains(x.TargetCategoryId)) .ToArrayAsync(); var outgoingLinksTask = CategoryLinks.Where(x => categoriesIds.Contains(x.SourceCategoryId)) .ToArrayAsync(); await Task.WhenAll(incommingLinksTask, outgoingLinksTask); } if (respGroup.HasFlag(CategoryResponseGroup.WithImages)) { var images = await Images.Where(x => categoriesIds.Contains(x.CategoryId)).ToArrayAsync(); } if (respGroup.HasFlag(CategoryResponseGroup.WithSeo)) { var seoInfos = await SeoInfos.Where(x => categoriesIds.Contains(x.CategoryId)).ToArrayAsync(); } //Load all properties meta information and information for inheritance if (respGroup.HasFlag(CategoryResponseGroup.WithProperties)) { //Load category property values by separate query var propertyValues = await PropertyValues.Include(x => x.DictionaryItem.DictionaryItemValues) .Where(x => categoriesIds.Contains(x.CategoryId)).ToArrayAsync(); var categoryPropertiesIds = await Properties.Where(x => categoriesIds.Contains(x.CategoryId)) .Select(x => x.Id).ToArrayAsync(); var categoryProperties = await GetPropertiesByIdsAsync(categoryPropertiesIds); } } } return(result); }
/// <summary> /// Reduce category details according to response group /// </summary> /// <param name="category"></param> /// <param name="respGroup"></param> protected virtual void ReduceDetails(Category category, CategoryResponseGroup responseGroup) { if (!responseGroup.HasFlag(CategoryResponseGroup.WithImages)) { category.Images = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithLinks)) { category.Links = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithParents)) { category.Parents = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithProperties)) { category.Properties = null; category.PropertyValues = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithOutlines)) { category.Outlines = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithSeo)) { category.SeoInfos = null; } }
public virtual Category[] GetByIds(string[] categoryIds, CategoryResponseGroup responseGroup, string catalogId = null) { var result = new List <Category>(); var preloadedCategoriesMap = PreloadCategories(catalogId); foreach (var categoryId in categoryIds.Where(x => x != null)) { Category category; if (preloadedCategoriesMap.TryGetValue(categoryId, out category)) { result.Add(MemberwiseCloneCategory(category)); } } //Reduce details according to response group foreach (var category in result) { if (!responseGroup.HasFlag(CategoryResponseGroup.WithImages)) { category.Images = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithLinks)) { category.Links = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithParents)) { category.Parents = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithProperties)) { category.Properties = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithOutlines)) { category.Outlines = null; } if (!responseGroup.HasFlag(CategoryResponseGroup.WithSeo)) { category.SeoInfos = null; } } return(result.ToArray()); }