public void Save(Employee employee) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { var user = session.Get <User>(1); var enterprise = session.Get <Enterprise>(1); user.Enterprises.Add(employee.Enterprise); enterprise.Users.Add(employee.User); session.Flush(); transacao.Commit(); } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao inserir relacionamento: " + e.Message); } } } }
public IList <T> Consultar() { using (ISession session = FluentSessionFactory.AbrirSession()) { return((from e in session.Query <T>() select e).ToList()); } }
public I GetById <I>(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <I>(id)); } }
public void Delete(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { Relationship relationShip = session.Get <Relationship>(id); if (relationShip != null) { session.Delete(relationShip); transacao.Commit(); } } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao deletar empresa: " + e.Message); } } } }
public void Delete(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { Enterprise enterprise = session.Get <Enterprise>(id); if (enterprise != null) { session.Delete(enterprise); transacao.Commit(); } } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao deletar Empresa: " + e.Message); } } } }
public IList <I> GetFunc <I>(System.Linq.Expressions.Expression <System.Func <I, bool> > ex) { using (ISession session = FluentSessionFactory.abrirSession()) { return((from e in session.Query <I>().Where(ex) select e).ToList()); } }
public void Delete(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { Relacionamentos relacionamentos = session.Get <Relacionamentos>(id); if (relacionamentos != null) { session.Delete(relacionamentos); transacao.Commit(); } } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao deletar usuário: " + e.Message); } } } }
public Enterprise GetById(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <Enterprise>(id)); } }
public IList <Relacionamentos> GetAll() { using (ISession session = FluentSessionFactory.abrirSession()) { return((from e in session.Query <Relacionamentos>() select e).ToList()); } }
public Relacionamentos GetById(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <Relacionamentos>(id)); } }
public User GetById(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <User>(id)); } }
public Relationship GetById(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <Relationship>(id)); } }
public void Delete(int id) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { T obj = session.Get <T>(id); if (obj != null) { session.Delete(obj); transacao.Commit(); } } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao deletar o registro: " + e.Message); } } } }
public T ObtemPorId(int id) { using (ISession session = FluentSessionFactory.AbrirSession()) { return(session.Get <T>(id)); } }
public IList <Enterprise> GetAll() { using (ISession session = FluentSessionFactory.abrirSession()) { return((from e in session.Query <Enterprise>() select e).ToList()); } }
public Morador BuscarPorCpf(Morador morador) { using (ISession session = FluentSessionFactory.AbrirSession()) { return(session.QueryOver <Morador>() .Where(p => p.cpf == morador.cpf).SingleOrDefault <Morador>()); } }
public IList <Morador> BuscarPorApartamento(int idApartamento) { using (ISession session = FluentSessionFactory.AbrirSession()) { return(session.QueryOver <Morador>() .Where(p => p.apartamento.id == idApartamento).List()); } }
public void CanCreateNHibernateSectionFactory() { const string DEFAULT_CONNECTION_STRING = "coonStringTcc"; var factory = FluentSessionFactory.GetSessionFactory("thread_static", DEFAULT_CONNECTION_STRING); Assert.IsFalse(factory.IsClosed); Assert.That(factory, Is.Not.Null); }
public Apartamento BuscarPorNomeNumeroBloco(Apartamento apartamento) { using (ISession session = FluentSessionFactory.AbrirSession()) { return(session.QueryOver <Apartamento>() .Where(p => p.nome == apartamento.nome && p.bloco == apartamento.bloco && p.numero == apartamento.numero) .SingleOrDefault <Apartamento>()); } }
public Usuario BuscarPorLogin(Usuario usuario) { using (ISession session = FluentSessionFactory.AbrirSession()) { return(session.QueryOver <Usuario>() .Where(p => p.login == usuario.login) .SingleOrDefault <Usuario>()); } }
public UserEnterprise GetById(int idUser, int idEnterprise) { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <UserEnterprise>(new UserEnterprise() { IdEnterprise = idEnterprise, IdUser = idUser })); } }
public void MyTestInitialize() { if (File.Exists(DataFile)) { File.Delete(DataFile); } _sut = new SqlUsersRepository(); var sessionFactory = new FluentSessionFactory(DataFile); sessionFactory.AfterPropertiesSet(); _sut.SessionFactory = (ISessionFactory)sessionFactory.GetObject(); File.ReadAllLines(@"CreateDbSchema.sql").ToList().ForEach(ExecuteCommand); }
public IList <Enterprise> GetAll() { try { using (ISession session = FluentSessionFactory.abrirSession()) { return((from e in session.Query <Enterprise>() select e).ToList()); } } catch (Exception e) { throw new Exception("Erro ao retornar empresas: " + e.Message); } }
public List <Employee> GetAll() { using (ISession session = FluentSessionFactory.abrirSession()) { var employees = (from e in session.Query <Enterprise>() from u in e.Users select new Employee { Enterprise = e, User = u }); return(employees.ToList()); } }
public Enterprise GetById(int id) { try { using (ISession session = FluentSessionFactory.abrirSession()) { return(session.Get <Enterprise>(id)); } } catch (Exception e) { throw new Exception("Erro ao retornar empresa por id: " + e.Message); } }
private static void RegisterNHibernatSectionAndFactory(ContainerBuilder builder) { builder.Register(x => FluentSessionFactory.GetSessionFactory("thread_static", "coonStringTcc")) .SingleInstance(); builder.RegisterType <NHibernateInterceptor>().SingleInstance().AsSelf(); builder.Register(x => { var session = x.Resolve <ISessionFactory>().OpenSession(x.Resolve <NHibernateInterceptor>()); session.FlushMode = FlushMode.Commit; return(session); }).InstancePerHttpRequest().OnRelease(x => x.Dispose()); }
private void Add(UserEnterprise userEnterprise) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { session.Save(userEnterprise); transacao.Commit(); } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao inserir usuario em empresa: " + e.Message); } } } }
private void Update(Enterprise enterprise) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { session.Update(enterprise); transacao.Commit(); } catch (Exception e) { if (!transacao.WasCommitted) { //transacao.Rollback(); } throw new Exception("Erro ao atualizar Empresa: " + e.Message); } } } }
public void Excluir(T entity) { using (ISession session = FluentSessionFactory.AbrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { session.Delete(entity); transacao.Commit(); } catch (Exception ex) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao exclcluir. " + ex.Message); } } } }
private void Add(EnterpriseUser enterpriseUser) { using (ISession session = FluentSessionFactory.abrirSession()) { using (ITransaction transacao = session.BeginTransaction()) { try { session.Save(enterpriseUser); transacao.Commit(); } catch (Exception e) { if (!transacao.WasCommitted) { transacao.Rollback(); } throw new Exception("Erro ao inserir Relacionamento: " + e.Message); } } } }