예제 #1
0
 public IList <T> Consultar()
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return((from e in session.Query <T>() select e).ToList());
     }
 }
예제 #2
0
 public T ObtemPorId(int id)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.Get <T>(id));
     }
 }
예제 #3
0
 public Morador BuscarPorCpf(Morador morador)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.QueryOver <Morador>()
                .Where(p => p.cpf == morador.cpf).SingleOrDefault <Morador>());
     }
 }
예제 #4
0
 public IList <Morador> BuscarPorApartamento(int idApartamento)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.QueryOver <Morador>()
                .Where(p => p.apartamento.id == idApartamento).List());
     }
 }
예제 #5
0
 public Usuario BuscarPorLogin(Usuario usuario)
 {
     using (ISession session = FluentSessionFactory.AbrirSession())
     {
         return(session.QueryOver <Usuario>()
                .Where(p => p.login == usuario.login)
                .SingleOrDefault <Usuario>());
     }
 }
예제 #6
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>());
     }
 }
예제 #7
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);
             }
         }
     }
 }
예제 #8
0
        public void Inserir(T entidade)
        {
            using (ISession session = FluentSessionFactory.AbrirSession())
            {
                using (ITransaction transacao = session.BeginTransaction())
                {
                    try
                    {
                        session.Save(entidade);
                        transacao.Commit();
                    } catch (Exception)
                    {
                        if (!transacao.WasCommitted)
                        {
                            transacao.Rollback();
                        }

                        throw;
                    }
                }
            }
        }