public Task <List <CategoryAttributeFullInfoView> > Handle(GetCategoryAttributesWithValuesQuery request, CancellationToken cancellationToken) => Task.Run(() => { var attributes = _categoryService.GetAllCategoryAttributesByCategoryId(request.CategoryId); var attributeMappings = _categoryService.GetCategoryAttributeMappingsByCategoryId(request.CategoryId); var mappedAttributes = AutoMapperConfiguration.Mapper.Map <List <CategoryAttributeFullInfoView> >(attributes); mappedAttributes.ForEach(attribute => { var attributeMapping = attributeMappings.FirstOrDefault(x => x.CategoryAttributeId == attribute.Id); attribute = AutoMapperConfiguration.Mapper.Map(attributeMapping, attribute); attribute.Values = AutoMapperConfiguration.Mapper.Map <IEnumerable <CategoryAttributeValueView> >(_categoryService.GetCategoryAttributeValues(attributeMapping.Id)); }); return(mappedAttributes); }, cancellationToken);
public Task <PagedList <CategoryView> > Handle(GetCategoriesQuery request, CancellationToken cancellationToken) { var storeId = _infrastructureService.Cache.Store.Id; var categories = _categoryService .GetAllCategories(string.Empty, storeId, request.Paged.PageIndex, request.Paged.PageSize, showHidden: true) .ConvertPagedList <Category, CategoryView>(); categories.Source.ForEach(c => { var categoryAttributeMappings = _categoryService.GetCategoryAttributeMappingsByCategoryId(c.Id); var categoryAttributes = _categoryService.GetAllCategoryAttributesByCategoryId(c.Id); c.Attributes = AutoMapperConfiguration.Mapper.Map <IEnumerable <CategoryAttributeMappingView> >(categoryAttributes); c.Attributes.ToList().ForEach(cAttribute => AutoMapperConfiguration.Mapper.Map(categoryAttributeMappings.FirstOrDefault(x => x.CategoryAttributeId == cAttribute.Id), cAttribute)); }); return(Task.FromResult(categories)); }