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));
        }
示例#2
0
 public Task <PagedList <CategoryShortInfoView> > Handle(GetCategoriesShortInfoQuery request, CancellationToken cancellationToken)
 => Task.Run(() => _categoryService
             .GetAllCategories(string.Empty, _infrastructureService.Cache.Store.Id, request.Paged.PageIndex,
                               request.Paged.PageSize, overridePublished: true)
             .ConvertPagedList <Category, CategoryShortInfoView>(), cancellationToken);