Exemple #1
0
 public AccountBalanceModel GetCardBalance(CardBalanceQuery query)
 {
     EnsureIsValid(query);
     try
     {
         var account = _deps.UserCards.SurelyFind(query.Id).Account;
         if (account == null)
         {
             throw new InvalidOperationException("Card should be bound to the account.");
         }
         var currency = string.IsNullOrEmpty(query.CurrencyISOName)
             ? account.Currency
             : _deps.Currencies.Find(query.CurrencyISOName);
         var balanceMoney = new Money(account.Currency, account.Balance);
         var balance      = new AccountBalanceModel
         {
             AccountNo         = account.AccountNo,
             AccountBalance    = account.Balance,
             AccountCurrency   = account.Currency.ToModel <CurrencyModel>(),
             RequestedCurrency = currency.ToModel <CurrencyModel>(),
             RequestedBalance  = _deps.MoneyConverter.Convert(balanceMoney, currency.ISOName).Amount
         };
         return(balance);
     }
     catch (ServiceException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't get account balance.", ex);
     }
 }
Exemple #2
0
 public IHttpActionResult Balance([FromUri] CardBalanceQuery query)
 {
     return(Ok(_cardAccountService.GetCardBalance(query)));
 }
Exemple #3
0
 public AccountBalanceModel GetCardBalance(CardBalanceQuery query)
 {
     EnsureIsValid(query);
     try
     {
         var account = _deps.UserCards.SurelyFind(query.Id).Account;
         if (account == null)
         {
             throw new InvalidOperationException("Card should be bound to the account.");
         }
         var currency = string.IsNullOrEmpty(query.CurrencyISOName)
             ? account.Currency
             : _deps.Currencies.Find(query.CurrencyISOName);
         var balanceMoney = new Money(account.Currency, account.Balance);
         var balance = new AccountBalanceModel
         {
             AccountNo = account.AccountNo,
             AccountBalance = account.Balance,
             AccountCurrency = account.Currency.ToModel<CurrencyModel>(),
             RequestedCurrency = currency.ToModel<CurrencyModel>(),
             RequestedBalance = _deps.MoneyConverter.Convert(balanceMoney, currency.ISOName).Amount
         };
         return balance;
     }
     catch (ServiceException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't get account balance.", ex);
     }
 }