示例#1
0
        public Task <Unit> Handle(DeleteCategoryAttributeValueCommand request, CancellationToken cancellationToken)
        {
            var categoryAttributeValue = _extendedCategoryService.GetCategoryAttributeValueById(request.Id);

            if (categoryAttributeValue == null)
            {
                throw new ValidationException(_localizationService.GetResource("DeleteCategoryAttributeValue.NotExists.Validation"));
            }

            _extendedCategoryService.DeleteCategoryAttributeValue(categoryAttributeValue);
            return(Unit.Task);
        }
        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);
        }