public DataService(IWebLog l) { symbols = new BaseRepository <DBSymbol>(); currencies = new BaseRepository <DBCurrency>(); settings = new BaseRepository <DBSettings>(); jobs = new BaseRepository <DBJobs>(); accstates = new BaseRepository <DBAccountstate>(); newsevents = new BaseRepository <DBNewsevent>(); accounts = new AccountsRepository(); experts = new ExpertsRepository(); persons = new AuthRepository(); wallets = new WalletsRepository(this); deals = new BaseRepository <DBDeals>(); log = l; rates = new List <Rates>(); }
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); }