/// <summary> /// Cancel the withdraw with the given WithdrawID /// </summary> /// <param name="cancelWithdrawCommand"> </param> /// <returns></returns> public CancelWithdrawResponse CancelWithdraw(CancelWithdrawCommand cancelWithdrawCommand) { if (_withdrawSubmissionService.CancelWithdraw(cancelWithdrawCommand.WithdrawId)) { Withdraw withdraw = _withdrawRepository.GetWithdrawByWithdrawId(cancelWithdrawCommand.WithdrawId); if (withdraw != null) { withdraw.StatusCancelled(); _fundsPersistenceRepository.SaveOrUpdate(withdraw); Balance balance = _balanceRepository.GetBalanceByCurrencyAndAccountId(withdraw.Currency, withdraw.AccountId); if (balance != null) { if (balance.CancelPendingTransaction(withdraw.WithdrawId, PendingTransactionType.Withdraw, withdraw.Amount + withdraw.Fee)) { _fundsPersistenceRepository.SaveOrUpdate(balance); return(new CancelWithdrawResponse(true)); } } throw new NullReferenceException(string.Format("No balance found for Currency = {0} | Account ID = {1}", withdraw.Currency.Name, withdraw.AccountId.Value)); } throw new NullReferenceException(string.Format("No withdraw found in the repository for Withdraw ID: {0}", cancelWithdrawCommand.WithdrawId)); } throw new ApplicationException(string.Format("Could not cancel withdraw with Withdraw ID: {0}", cancelWithdrawCommand.WithdrawId)); }