Example #1
0
        private static IEnumerable <TimeWarpUser> GetUsersFromRepository(ITimeWarpStateCalculator timeWarpStateCalculator)
        {
            IList <TimeWarpUserState> userStates;

            //todo: optimize this crap.
            using (var session = new NHibernateSessionPerRequest <TimeWarpUserStateClassMap>())
            {
                var accountRespository = new TimeWarpAccountRepository(session.GetCurrentSession());
                var accounts           = accountRespository.GetAll();

                var userStateRepository = new TimeWarpUserStateRepository(session.GetCurrentSession());

                userStates = new List <TimeWarpUserState>();
                foreach (var account in accounts)
                {
                    var latestState = userStateRepository.GetLatestStateByAccountId(account.Id);
                    if (latestState != null)
                    {
                        NHibernateUtil.Initialize(latestState.Account);
                        userStates.Add(userStateRepository.GetLatestStateByAccountId(account.Id));
                    }
                }
            }

            return(userStates.Select(x => new TimeWarpUser(x, timeWarpStateCalculator)));
        }
Example #2
0
        private static TimeWarpUserState UpdateValuesInDatabase(Account account)
        {
            var repository = new TimeWarpUserStateRepository();
            TimeWarpUserState timeWarpUserState = repository.GetLatestStateByAccountId(account.Id);

            return(timeWarpUserState);
        }
 public void SaveState(TimeWarpUserState newState)
 {
     //this should probably be on a new thread...and exception handling. logging ..etc
     using (var session = new NHibernateSessionPerRequest <TimeWarpUserStateClassMap>())
     {
         var repository = new TimeWarpUserStateRepository(session.GetCurrentSession());
         repository.Add(newState);
     }
 }
Example #4
0
        private static void CreateInitialValuesInDatabase(Account account, TimeWarpUserState state1, TimeWarpUserState state2)
        {
            var accountRepository = new AccountRepository();

            accountRepository.Add(account);

            var repository = new TimeWarpUserStateRepository();

            repository.Add(state1);
            repository.Add(state2);
        }