/// <summary>
        /// Creates a transaction in result of a Deposit
        /// </summary>
        /// <param name="deposit"> </param>
        /// <param name="balance"> </param>
        /// <returns></returns>
        public bool CreateDepositTransaction(Deposit deposit, decimal balance)
        {
            if (deposit != null)
            {
                // double currenctBalance = _ledgerRepository.GetBalanceForCurrency(deposit.Currency.Name,
                //    new AccountId(deposit.AccountId.Value));

                Ledger ledger = new Ledger(_ledgerIdGeneraterService.GenerateLedgerId(), DateTime.Now,
                                           LedgerType.Deposit, deposit.Currency, deposit.Amount,
                                           _limitsConfigurationService.ConvertCurrencyToFiat(deposit.Currency.Name, deposit.Amount),
                                           balance, null, null, null, deposit.DepositId,
                                           deposit.AccountId);
                _fundsPersistenceRepository.SaveOrUpdate(ledger);
                Log.Debug(string.Format("Ledger Deposit Transaction saved: Currency = {0} | Account ID = {1} | " +
                                        "Amount = {2} | Fee = {3} | Balance = {4} | DepositID = {5} | Address = {6} | " +
                                        "TransactionID = {7} | DateTime = {8}",
                                        deposit.Currency.Name, deposit.AccountId.Value, deposit.Amount, deposit.Fee, balance,
                                        deposit.DepositId, deposit.BitcoinAddress, deposit.TransactionId, deposit.Date));
                return(true);
            }
            return(false);
        }
        public Withdraw ValidateFundsForWithdrawal(AccountId accountId, Currency currency, decimal amount, TransactionId
                                                   transactionId, BitcoinAddress bitcoinAddress)
        {
            Tuple <bool, string> isTierVerified = IsTierVerified(accountId.Value, currency.IsCryptoCurrency);

            if (isTierVerified.Item1)
            {
                //if (currency.IsCryptoCurrency)
                //{
                WithdrawFees withdrawFees = _withdrawFeesRepository.GetWithdrawFeesByCurrencyName(currency.Name);
                if (withdrawFees != null)
                {
                    // Check if the current withdrawal amount is greater than the amount required mentioned with the Fees
                    if (amount >= withdrawFees.MinimumAmount)
                    {
                        Balance balance = GetBalanceForAccountId(accountId, currency);
                        if (balance != null)
                        {
                            // Get all the Withdraw Ledgers
                            IList <Withdraw> withdrawals = GetWithdrawalLedgers(currency, accountId);

                            // Evaluate if the current withdrawal is within the limits of the maximum withdrawal allowed and
                            // the balance available
                            if (_limitsConfigurationService.EvaluateWithdrawLimits(currency.Name, isTierVerified.Item2,
                                                                                   amount, withdrawals, balance.AvailableBalance, balance.CurrentBalance))
                            {
                                Withdraw withdraw = new Withdraw(currency, _withdrawIdGeneratorService.GenerateNewId(),
                                                                 DateTime.Now, GetWithdrawType(currency.Name),
                                                                 amount - withdrawFees.Fee,
                                                                 withdrawFees.Fee,
                                                                 TransactionStatus.Pending, accountId,
                                                                 bitcoinAddress);
                                // Set amount In US Dollars, which will be used in later calculations regarding withdrawals
                                withdraw.SetAmountInUsd(_limitsConfigurationService.ConvertCurrencyToFiat(currency.Name, amount));
                                _fundsPersistenceRepository.SaveOrUpdate(withdraw);
                                balance.AddPendingTransaction(withdraw.WithdrawId, PendingTransactionType.Withdraw,
                                                              -(withdraw.Amount + withdrawFees.Fee));
                                _fundsPersistenceRepository.SaveOrUpdate(balance);
                                return(withdraw);
                            }
                            else
                            {
                                throw new InvalidOperationException("Not enough balance or withdraw limit reached");
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format("No balance available AccountID = {0} | Currency = {1}", accountId.Value, currency.Name));
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Withdraw amount less than Minimum Amount: " +
                                                                          "AccountID = {0} | Currency = {1}", accountId.Value, currency.Name));
                    }
                }
                else
                {
                    throw new InstanceNotFoundException(string.Format("No Withdraw Fees Found: " +
                                                                      "AccountID = {0} | Currency = {1}", accountId.Value, currency.Name));
                }
            }
            else
            {
                throw new InvalidOperationException(string.Format("Required Tier not verified for Withdraw: Account ID = {0}",
                                                                  accountId.Value));
            }
        }