public async Task <IActionResult> ConvertWalletCurrency([FromBody] WalletConversionDTO walletConversion)
        {
            if (walletConversion == null ||
                !walletConversion.UserId.HasValue ||
                walletConversion.Amount <= 0)
            {
                return(BadRequest("Invalid model."));
            }

            var result = await _walletSrv.ConvertWalletCurrencyAsync(walletConversion);

            if (result.IsSuccess)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public async Task <OperationResult <UserWalletsDTO> > ConvertWalletCurrencyAsync
            (WalletConversionDTO walletConversion)
        {
            if (!walletConversion.UserId.HasValue)
            {
                throw new ArgumentNullException(nameof(walletConversion.UserId), "User ID must not be null.");
            }

            var user = _userService.Get(walletConversion.UserId.Value);

            if (user == null)
            {
                user = await _userService.CreateUserAsync();

                return(OperationResultBuilder <UserWalletsDTO> .BuildError(null,
                                                                           "New user does not have actual wallets."));
            }

            if (!await _currencySrv.IsExists(walletConversion.BaseCurrency) ||
                !await _currencySrv.IsExists(walletConversion.TargetCurrency))
            {
                return(OperationResultBuilder <UserWalletsDTO> .BuildError(null,
                                                                           "Currency does not exist or is not supported."));
            }

            var baseWallet = _walletRepo.Data
                             .FirstOrDefault(w =>
                                             w.UserFK.Equals(user.Id) &&
                                             string.Equals(w.CurrencyISOCode, walletConversion.BaseCurrency,
                                                           StringComparison.InvariantCultureIgnoreCase));

            if (baseWallet == null)
            {
                return(OperationResultBuilder <UserWalletsDTO> .BuildError(null, "Base wallet does not exist."));
            }

            var targetWallet = _walletRepo.Data
                               .FirstOrDefault(w =>
                                               w.UserFK.Equals(user.Id) &&
                                               string.Equals(w.CurrencyISOCode, walletConversion.TargetCurrency,
                                                             StringComparison.InvariantCultureIgnoreCase));

            if (targetWallet == null)
            {
                targetWallet = new Wallet()
                {
                    UserFK          = user.Id,
                    CurrencyISOCode = walletConversion.TargetCurrency
                };

                await _walletRepo.AddAsync(targetWallet);
            }

            var conversionRate = await _currencySrv.GetConversionRate
                                     (walletConversion.BaseCurrency, walletConversion.TargetCurrency);

            var targetCurrencyAmount = walletConversion.Amount * conversionRate;

            baseWallet.Amount   -= walletConversion.Amount;
            targetWallet.Amount += targetCurrencyAmount;
            await _walletRepo.UpdateAsync(new[] { baseWallet, targetWallet });

            return(await GetUserWalletsAsync(user.Id));
        }