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); } }
// 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())); }
public static ISession GetCurrentSession() { return(NHibernateSessionPerRequest.GetCurrentSession()); }
public Repository() { session = NHibernateSessionPerRequest.GetCurrentSession(); }