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);
                    }
                }
            }
        }
Example #2
0
 public IList <T> Consultar()
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return((from e in session.Query <T>() select e).ToList());
     }
 }
Example #3
0
 public I GetById <I>(int id)
 {
     using (ISession session = FluentSessionFactory.abrirSession())
     {
         return(session.Get <I>(id));
     }
 }
Example #4
0
 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);
             }
         }
     }
 }
Example #5
0
 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);
             }
         }
     }
 }
Example #6
0
 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);
             }
         }
     }
 }
Example #8
0
 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));
     }
 }
Example #11
0
 public User GetById(int id)
 {
     using (ISession session = FluentSessionFactory.abrirSession())
     {
         return(session.Get <User>(id));
     }
 }
Example #12
0
 public Relationship GetById(int id)
 {
     using (ISession session = FluentSessionFactory.abrirSession())
     {
         return(session.Get <Relationship>(id));
     }
 }
Example #13
0
 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);
             }
         }
     }
 }
Example #14
0
 public T ObtemPorId(int id)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.Get <T>(id));
     }
 }
Example #15
0
 public IList <Enterprise> GetAll()
 {
     using (ISession session = FluentSessionFactory.abrirSession())
     {
         return((from e in session.Query <Enterprise>() select e).ToList());
     }
 }
Example #16
0
 public Morador BuscarPorCpf(Morador morador)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.QueryOver <Morador>()
                .Where(p => p.cpf == morador.cpf).SingleOrDefault <Morador>());
     }
 }
Example #17
0
 public IList <Morador> BuscarPorApartamento(int idApartamento)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.QueryOver <Morador>()
                .Where(p => p.apartamento.id == idApartamento).List());
     }
 }
Example #18
0
        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);
        }
Example #19
0
 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>());
     }
 }
Example #20
0
 public Usuario BuscarPorLogin(Usuario usuario)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.QueryOver <Usuario>()
                .Where(p => p.login == usuario.login)
                .SingleOrDefault <Usuario>());
     }
 }
Example #21
0
 public UserEnterprise GetById(int idUser, int idEnterprise)
 {
     using (ISession session = FluentSessionFactory.abrirSession())
     {
         return(session.Get <UserEnterprise>(new UserEnterprise()
         {
             IdEnterprise = idEnterprise, IdUser = idUser
         }));
     }
 }
Example #22
0
        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);
        }
Example #23
0
 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());
            }
        }
Example #25
0
 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);
     }
 }
Example #26
0
        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());
        }
Example #27
0
 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);
             }
         }
     }
 }
Example #28
0
 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);
             }
         }
     }
 }
Example #29
0
 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);
             }
         }
     }
 }