Пример #1
0
        public async Task <ActionResultResponse> Delete(string tenantId, string productAttributeId, string productAttributeValueId)
        {
            var isProductAttributeExists = await _attributeRepository.CheckExists(productAttributeId, tenantId);

            if (!isProductAttributeExists)
            {
                return(new ActionResultResponse(-1, _warehouseResourceService.GetString("Product attribute does not exists.")));
            }

            var info = await _attributeValueRepository.GetInfo(productAttributeValueId);

            if (info == null)
            {
                return(new ActionResultResponse(-2, _warehouseResourceService.GetString("Product attribute value does not exists.")));
            }

            if (info.TenantId != tenantId)
            {
                return(new ActionResultResponse(-3, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            if (info.AttributeId != productAttributeId)
            {
                return(new ActionResultResponse(-4, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            var isProductValueExists = await _productAttributeRepository.CheckExistProductAttributeValueId(productAttributeId, tenantId);

            if (isProductValueExists)
            {
                return(new ActionResultResponse(-2, _warehouseResourceService.GetString
                                                    ("This product attribute value has been used by product.You can not delete this product attribute value.")));
            }

            var result = await _attributeValueRepository.Delete(productAttributeValueId);

            await _attributeValueTranslationRepository.Delete(productAttributeValueId);

            return(new ActionResultResponse(result, _warehouseResourceService.GetString("Delete product attribute value successful.")));
        }