public Task <Unit> Handle(LinkCategoryAttributeValueCommand request, CancellationToken cancellationToken)
        {
            Valid(request);
            foreach (var categoryAttributeValue in request.CategoryAttributeValues)
            {
                if (categoryAttributeValue.Id.HasValue)
                {
                    var updateCategoryAttributeValue = _extendedCategoryService.GetCategoryAttributeValueById(categoryAttributeValue.Id.Value);
                    updateCategoryAttributeValue = AutoMapperConfiguration.Mapper.Map(categoryAttributeValue, updateCategoryAttributeValue);
                    _extendedCategoryService.UpdateCategoryAttributeValue(updateCategoryAttributeValue);

                    continue;
                }

                var categoryAttribute = _extendedCategoryService
                                        .GetCategoryAttributeMappingsByCategoryId(request.CategoryId).First(am => am.CategoryAttributeId == categoryAttributeValue.CategoryAttributeId);
                var addAttributeValue = AutoMapperConfiguration.Mapper.Map <CategoryAttributeValue>(categoryAttributeValue);
                addAttributeValue.CategoryAttributeMappingId = categoryAttribute.Id;
                _extendedCategoryService.InsertCategoryAttributeValue(addAttributeValue);
            }

            return(Unit.Task);
        }
示例#2
0
        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));
        }