示例#1
0
        public async Task <ValidationResult> ValidateRemoveAllWishList(RemoveAllWishListInput input)
        {
            ValidationResult validationResult = new();

            if (string.IsNullOrWhiteSpace(input.CustomerEmail))
            {
                validationResult.Messages.Add(new(nameof(RemoveAllWishListInput.CustomerEmail), "Debe indicar un cliente."));
            }
            else
            {
                Customer customer = await _customerRepository.GetCustomer(input.CustomerEmail);

                if (customer is null)
                {
                    validationResult.Messages.Add(new(nameof(RemoveAllWishListInput.CustomerEmail), "No existe el cliente."));
                }
                else
                {
                    WishList wishList = await _wishListRepository.GetByCustomerAsync(input.CustomerEmail);

                    if (wishList is null)
                    {
                        validationResult.Messages.Add(new(nameof(RemoveAllWishListInput.CustomerEmail), "El cliente no posee una wishlist"));
                    }
                }
            }

            return(validationResult);
        }
        public async Task <OperationResult <WishListDto> > RemoveAllWishListAsync(RemoveAllWishListInput input)
        {
            var validatioResult = await _validator.ValidateRemoveAllWishList(input);

            if (validatioResult.IsSuccess)
            {
                var wishlist = await _repository.GetByCustomerAsync(input.CustomerEmail);

                wishlist.Products = Enumerable.Empty <string>();

                await _repository.UpdateAsync(wishlist);

                return(OperationResult <WishListDto> .Success(wishlist.ConvertToDto()));
            }

            return(OperationResult <WishListDto> .Fail(validatioResult));
        }