private T GetUser <T>(string Username) where T : User { T User = default(T); using (var session = NHibernateService.OpenSession()) { try { using (var transaction = session.BeginTransaction()) { User = session.QueryOver <T>().Where(c => c.Username == Username).SingleOrDefault(); transaction.Commit(); } session.Clear(); //session.Close(); } catch (Exception e) { Logger.Log(e); return(null); } } return(User); }
public IQueryable <T> All() { using (ISession session = NHibernateService.OpenSession()) { return(session.Query <T>().ToList().AsQueryable()); } }
private T GetUser <T>(int Id) where T : User { T User = default(T); using (var session = NHibernateService.OpenSession()) { try { using (var transaction = session.BeginTransaction()) { // User = session.QueryOver<User>().Where(c => c.Id == Id) // .And(c => c is T).SingleOrDefault(); User = (T)session.Get(typeof(T), Id); transaction.Commit(); } session.Clear(); //session.Close(); } catch (Exception e) { Logger.Log(e); return(User); } } return(User); }
public override bool Add(Employee entity) { var list = All(); foreach (var currentEmployee in list) { if (currentEmployee.Oib.Equals(entity.Oib)) { throw new EmployeeWithOibAlreadyExistsException("Employee with this OIB already exists!"); } } using (ISession session = NHibernateService.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(entity); transaction.Commit(); } } NotifyObservers(); return(true); }
public override bool Add(VideoWall entity) { var list = All(); foreach (var currentVideoWall in list) { if (currentVideoWall.Location.Equals(entity.Location)) { throw new VideoWallAtLocationAlreadyExistsException("Video wall already exists in database!"); } } using (ISession session = NHibernateService.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(entity); transaction.Commit(); } } NotifyObservers(); return(true); }
private IList <T> getAllAds <T>() where T : Ad { IList <T> Ads = null; using (var session = NHibernateService.OpenSession()) { try { using (var transaction = session.BeginTransaction()) { Ads = session.QueryOver <T>().List(); transaction.Commit(); } session.Clear(); // session.Close(); } catch (Exception e) { Logger.Log(e); return(null); } } // return Ads.OrderBy(o => o.Id).ToList(); return(Ads); }
static void Main() { ISession _session = NHibernateService.OpenSession(); IRepositoryFactory _repositoryFactory = new RepositoryFactory(_session); IWindowFormsFactory _formsFactory = new WindowFormsFactory(); IUserRepository _userRepository = _repositoryFactory.GetUserRepository(); IInitialRunController _initialRunController = new InitialRunController(_formsFactory, _repositoryFactory); IUserController _userController = new UserController(_formsFactory, _repositoryFactory); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); List <User> users = _userRepository.GetAllUsers(); if (users.Count == 0) { Application.Run(new frmStartCalorieLimitWindow(_initialRunController, _userController, _repositoryFactory)); } else { IFoodDatabaseController _foodDatabaseController = new FoodDatabaseController(_formsFactory, _repositoryFactory); IFoodController _foodController = new FoodController(_formsFactory, _repositoryFactory); Application.Run(new frmDailyIntakeWindow(_foodDatabaseController, _foodController, _repositoryFactory, users[0])); } }
public override bool Add(Schedule entity) { var list = All(); foreach (var currentSchedule in list) { if (currentSchedule.Name.Equals(entity.Name)) { throw new ScheduleWithNameAlreadyExistsException(); } } using (ISession session = NHibernateService.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(entity); transaction.Commit(); } } NotifyObservers(); return(true); }
public T FindBy(Expression <Func <T, bool> > expression) { using (ISession session = NHibernateService.OpenSession()) { return(session.Query <T>() .Where(expression).FirstOrDefault()); } }
public override VideoWall FindBy(int id) { using (ISession session = NHibernateService.OpenSession()) { return(session .Query <VideoWall>().SingleOrDefault(x => x.Id == id)); } }
public bool Delete(T entity) { using (ISession session = NHibernateService.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Delete(entity); transaction.Commit(); } } NotifyObservers(); return(true); }
public override bool Add(RentWall entity) { using (ISession session = NHibernateService.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(entity); transaction.Commit(); } } NotifyObservers(); return(true); }
public List <Postupak> DohvatiSDetaljimaPostupkePoDatumu(int idVeterinar, DateTime datum) { using (ISession session = NHibernateService.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { var lista = session.Query <Postupak>().Where(x => x.VrstaPostupka.Veterinar.Id == idVeterinar && x.Datum.Value.Date.Equals(datum.Date)) .Fetch(x => x.Zivotinja) .Fetch(x => x.VrstaPostupka) .FetchMany(x => x.Lijeks) .FetchMany(x => x.Bolests) .ToList(); return(lista); } } }
static void Main() { ISession session = NHibernateService.OpenSession(); WindowsFormsFactory _formsFactory = new WindowsFormsFactory(); ITeamRepository _teamRepository = new TeamRepository(session); IGameRepository _gameRepository = new GameRepository(session); IGroupRepository _groupRepository = new GroupRepository(session); InitialFormController initialFormController = new InitialFormController(_formsFactory, _teamRepository, _gameRepository, _groupRepository); initialFormController.LoadDefaultModel(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmInitialForm(initialFormController)); }
public bool DeleteUser(User User) { using (var session = NHibernateService.OpenSession()) { try { using (var transaction = session.BeginTransaction()) { session.Delete(User); transaction.Commit(); } session.Clear(); //session.Close(); } catch (Exception e) { Logger.Log(e); return(false); } } return(true); }
private IList <T> GetAllUsers <T>() where T : User { IList <T> Users = null; using (var session = NHibernateService.OpenSession()) { try { using (var transaction = session.BeginTransaction()) { Users = session.QueryOver <T>().List(); transaction.Commit(); } session.Clear(); // session.Close(); } catch (Exception e) { Logger.Log(e); return(null); } } return(Users); }