public async Task <ValidationResult> ValidateUpdateProductNameDescription(UpdateProductNameDescriptionInput input) { ValidationResult validationResult = new(); Product product = await _productRepository.GetAsync(input.ProductId); if (product is null) { validationResult.Messages.Add(new(nameof(UpdateProductNameDescriptionInput.ProductId), "El producto no existe.")); } else if (string.IsNullOrWhiteSpace(input.Name)) { validationResult.Messages.Add(new(nameof(UpdateProductNameDescriptionInput.Name), "El nombre del producto no puede estar vacio.")); } else if (string.IsNullOrWhiteSpace(input.Description)) { validationResult.Messages.Add(new(nameof(UpdateProductNameDescriptionInput.Description), "La descripción del producto no puede estar vacio.")); } return(validationResult); }
public async Task <OperationResult <ProductDto> > UpdateProductNameDescriptionAsync(UpdateProductNameDescriptionInput input) { ValidationResult validationResult = await _validator.ValidateUpdateProductNameDescription(input); if (validationResult.IsSuccess) { Product product = await _repository.GetAsync(input.ProductId); product.Name = input.Name; await _repository.UpdateAsync(product); ProductOverview productOverview = await _overviewRepository.GetByProduct(product); if (productOverview is null) { productOverview = new() { ProductId = product.Id, Description = input.Description }; await _overviewRepository.CreateAsync(productOverview); } else { productOverview.Description = input.Description; await _overviewRepository.UpdateAsync(productOverview); } return(OperationResult <ProductDto> .Success(product.ConvertToDto())); } else { return(OperationResult <ProductDto> .Fail(validationResult)); } }
public async Task <IActionResult> UpdateNameDescription(UpdateProductNameDescriptionInput input) { var result = await _productService.UpdateProductNameDescriptionAsync(input); return(new OperationActionResult(result)); }