public async Task <ValidationResult> ValidateRemoveAllBasketAsync(RemoveAllBasketInput input) { ValidationResult validationResult = new(); if (string.IsNullOrWhiteSpace(input.CustomerEmail)) { validationResult.Messages.Add(new(nameof(AddBasketProductInput.CustomerEmail), $"Debe ingresar un cliente.")); } else { Customer customer = await _customerRepository.GetCustomer(input.CustomerEmail); if (customer is null) { validationResult.Messages.Add(new(nameof(AddBasketProductInput.CustomerEmail), $"El usuario '{input.CustomerEmail}' no existe.")); } } Basket basket = await _basketRepository.GetByCustomerAsync(input.CustomerEmail); if (basket is null) { validationResult.Messages.Add(new(nameof(RemoveAllBasketInput.CustomerEmail), $"El carrito no existe.")); } return(validationResult); }
public async Task <OperationResult> RemoveAllBasketAsync(RemoveAllBasketInput input) { var validatioResult = await _validator.ValidateRemoveAllBasketAsync(input); if (validatioResult.IsSuccess) { var basket = await _repository.GetByCustomerAsync(input.CustomerEmail); basket.Products = Enumerable.Empty <ProductDefinitive>(); await _repository.UpdateAsync(basket); return(OperationResult <BasketDto> .Success(basket.ConvertToDto())); } return(OperationResult <BasketDto> .Fail(validatioResult)); }