Exemplo n.º 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)));
        }
 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);
     }
 }
Exemplo n.º 3
0
        // GET api/values
        public IEnumerable <RoomInfo> Get()
        {
            IList <Domain.Entities.Room> rooms;

            using (var session = new NHibernateSessionPerRequest <RoomClassMap>())
            {
                RoomRepository roomRepository = new RoomRepository(session.GetCurrentSession());

                rooms = roomRepository.GetAll();
            }

            return(rooms.Select(r => r.ConvertToPublicV001()));
        }
Exemplo n.º 4
0
 public static ISession GetCurrentSession()
 {
     return(NHibernateSessionPerRequest.GetCurrentSession());
 }
Exemplo n.º 5
0
 public Repository()
 {
     session = NHibernateSessionPerRequest.GetCurrentSession();
 }