示例#1
0
 public Terminal getTerminalByNumber(ISession Session, long AccountNumber)
 {
     try
     {
         var result = Session.Query <DBTerminal>().Where(x => x.Accountnumber == (int)AccountNumber);
         if (result.Any())
         {
             var      term     = result.FirstOrDefault();
             Terminal terminal = new Terminal();
             if ((term != null) && accounts.toDTO(term, ref terminal))
             {
                 return(terminal);
             }
         }
     }
     catch (Exception e)
     {
         log.Error("Error: getTerminalByNumber: " + e);
     }
     return(null);
 }
示例#2
0
        public List <Wallet> GetWalletsState(DateTime forDate)
        {
            List <Wallet> results = new List <Wallet>();

            try
            {
                using (ISession Session = ConnectionHelper.CreateNewSession())
                {
                    var rateList = Session.Query <DBRates>().Where(x => x.Retired == false).ToList();
                    IQueryable <DBWallet> wallets = null;
                    if (forDate == DateTime.MaxValue)
                    {
                        wallets = Session.Query <DBWallet>()
                                  .Where(x => x.Retired == false && !x.Name.Equals("test"));
                    }
                    else
                    {
                        wallets = Session.Query <DBWallet>().Where(x => !x.Name.Equals("test"));
                    }

                    foreach (var dbw in wallets)
                    {
                        Wallet  wallet  = toDTO(dbw);
                        decimal balance = 0;
                        IQueryable <DBAccount> accounts = null;
                        if (forDate == DateTime.MaxValue)
                        {
                            accounts = Session.Query <DBAccount>()
                                       .Where(x => x.Wallet.Id == wallet.Id && x.Retired == false);
                        }
                        else
                        {
                            accounts = Session.Query <DBAccount>().Where(x => x.Wallet.Id == wallet.Id);
                        }

                        foreach (var acc in accounts)
                        {
                            Account account = new Account();
                            if (AccountsRepository.toDTO(acc, ref account))
                            {
                                DBAccountstate accState = null;
                                IQueryable <DBAccountstate> accResults = null;
                                if (forDate.Equals(DateTime.MaxValue))
                                {
                                    accResults = Session.Query <DBAccountstate>()
                                                 .Where(x => x.Account.Id == acc.Id)
                                                 .OrderByDescending(x => x.Date);
                                }
                                else
                                {
                                    accResults = Session.Query <DBAccountstate>()
                                                 .Where(x => x.Account.Id == acc.Id && x.Date <= forDate)
                                                 .OrderByDescending(x => x.Date);
                                }

                                if (accResults == null || accResults.Count() == 0)
                                {
                                    continue;
                                }
                                // acc.Currency.Id
                                accState = accResults.FirstOrDefault();
                                if (accState != null)
                                {
                                    account.Balance = accState.Balance;
                                    decimal value = account.Balance;
                                    if (acc.Currency != null)
                                    {
                                        value = parent.ConvertToUSD(account.Balance, acc.Currency.Name);
                                    }
                                    balance += value;
                                }
                                wallet.Accounts.Add(account);
                            }
                        }
                        wallet.Balance = balance;
                        results.Add(wallet);
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("GetWalletsState for Date: " + forDate.ToString(xtradeConstants.MTDATETIMEFORMAT) +
                          e);
            }

            return(results);
        }