public async Task <OperationResult> DeleteAsync(DeleteProductVariantInput input) { var validationResult = await _productVariantValidator.ValidateDeleteProductVariant(input); if (validationResult.IsSuccess) { var entity = await _productVariantRepository.GetByNameAsync(new() { Id = input.ProductId }, input.Name); await _productVariantRepository.RemoveAsync(entity); return(OperationResult.Success()); } return(OperationResult.Fail(validationResult)); }
public async Task <ValidationResult> ValidateDeleteProductVariant(DeleteProductVariantInput input) { ValidationResult validationResult = new(); var product = await _productRepository.GetAsync(input.ProductId); if (product is null) { validationResult.Messages.Add(new(nameof(DeleteProductVariantInput.ProductId), "El producto no existe.")); } else { var productVariant = await _productVariantRepository.GetByNameAsync(product, input.Name); if (productVariant is null) { validationResult.Messages.Add(new(nameof(DeleteProductVariantInput.Name), "La variante no existe.")); } } return(validationResult); }