예제 #1
0
        public async Task <ValidationResult> ValidateUpdateProductCostPrice(UpdateProductCostPriceInput input)
        {
            ValidationResult validationResult = new();

            Product product = await _productRepository.GetAsync(input.ProductId);

            if (product is null)
            {
                validationResult.Messages.Add(new(nameof(UpdateProductCostPriceInput.ProductId), "El producto no existe."));
            }
            else
            {
                if (input.Cost < 0)
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductCostPriceInput.Cost), "El costo debe ser mayor o igual a cero."));
                }

                if (input.Price <= 0)
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductCostPriceInput.Price), "El precio debe ser mayor a cero."));
                }

                if (input.Price < input.Cost)
                {
                    validationResult.Messages.Add(new(nameof(UpdateProductCostPriceInput.Price), "El precio no puede ser menor que el costo."));
                }
            }

            return(validationResult);
        }
예제 #2
0
        public async Task <OperationResult <ProductDto> > UpdateProductCostPriceAsync(UpdateProductCostPriceInput input)
        {
            var validationResult = await _validator.ValidateUpdateProductCostPrice(input);

            if (validationResult.IsSuccess)
            {
                Product product = await _repository.GetAsync(input.ProductId);

                product.Cost  = input.Cost;
                product.Price = input.Price;

                await _repository.UpdateAsync(product);

                return(OperationResult <ProductDto> .Success(product.ConvertToDto()));
            }
            else
            {
                return(OperationResult <ProductDto> .Fail(validationResult));
            }
        }
        public async Task <IActionResult> UpdateCostPrice(UpdateProductCostPriceInput input)
        {
            var result = await _productService.UpdateProductCostPriceAsync(input);

            return(new OperationActionResult(result));
        }