public Task <Unit> Handle(DeleteCategoryAttributeCommand request, CancellationToken cancellationToken)
        {
            var categoryAttribute = _extendedCategoryService.GetCategoryAttribute(request.Id)
                                    ?? throw new ValidationException(
                                              _localizationService.GetResource("DeleteCategoryAttribute.NotExists.Validation"));

            if (_extendedCategoryService.HasAnyMappings(categoryAttribute.Id))
            {
                throw new ValidationException(_localizationService.GetResource("DeleteCategoryAttribute.IsLinkedWithCategory.Validation"));
            }

            _extendedCategoryService.DeleteCategoryAttribute(categoryAttribute);
            return(Unit.Task);
        }
        public Task <Unit> Handle(CreateUpdateCategoryAttributeCommand request, CancellationToken cancellationToken)
        {
            CategoryAttribute categoryAttribute;

            if (request.Id.HasValue)
            {
                categoryAttribute = _extendedCategoryService.GetCategoryAttribute(request.Id.Value);
                categoryAttribute = AutoMapperConfiguration.Mapper.Map <CreateUpdateCategoryAttributeCommand, CategoryAttribute>(request, categoryAttribute);
                _extendedCategoryService.UpdateCategoryAttribute(categoryAttribute);

                return(Unit.Task);
            }

            categoryAttribute = AutoMapperConfiguration.Mapper.Map <CategoryAttribute>(request);
            _extendedCategoryService.InsertCategoryAttribute(categoryAttribute);

            return(Unit.Task);
        }
        private void Valid(LinkCategoryAttributeValueCommand request)
        {
            var categoryId          = request.CategoryId;
            var categoryAttributes  = _extendedCategoryService.GetCategoryAttributeMappingsByCategoryId(categoryId);
            var attributesNotLinked = request.CategoryAttributeValues.Select(x => x.CategoryAttributeId).Distinct()
                                      .Except(categoryAttributes.Select(x => x.CategoryAttributeId));

            if (!attributesNotLinked?.Any() ?? true)
            {
                return;
            }

            var categoryAttributeId   = request.CategoryAttributeValues.First(cav => categoryAttributes.All(ca => ca.Id != cav.CategoryAttributeId)).CategoryAttributeId;
            var categoryAttributeName = _extendedCategoryService.GetCategoryAttribute(categoryAttributeId).Name;
            var message =
                _localizationService.GetResource(
                    "LinkCategoryAttributeValue.CategoryAttributeNotLinkedWithCategory.Validation");

            throw new ValidationException(string.Format(message, categoryAttributeName));
        }