public static List<FormaPagamento> All()
 {
     using (OikoDataContext db = new OikoDataContext())
     {
         return db.FormaPagamento.OrderBy(fp => fp.id).ToList();
     }
 }
 public static List<Categoria> All()
 {
     using (OikoDataContext db = new OikoDataContext())
     {
         return db.Categoria.OrderBy(c => c.id).ToList();
     }
 }
Example #3
0
 public static List<Usuario> All()
 {
     using (OikoDataContext db = new OikoDataContext())
     {
         return db.Usuario.OrderBy(u => u.id).ToList();
     }
 }
Example #4
0
 public static List<Conta> all()
 {
     using (OikoDataContext db = new OikoDataContext())
     {
         return db.Conta.OrderBy(c => c.id).ToList();
     }
 }
 public static List<Lancamento> all()
 {
     using (OikoDataContext db = new OikoDataContext())
     {
         return db.Lancamento.OrderBy(l => l.id).ToList();
     }
 }
        public static void baixa(int id, DateTime dataRecebimentoPagamento, int idConta)
        {
            try
            {
                using (OikoDataContext db = new OikoDataContext())
                {
                    Lancamento lancamento = db.Lancamento.SingleOrDefault(l => l.id == id);
                    if (lancamento == null)
                    {
                        throw new Exception(
                            string.Format("O lancamento com id {0} não foi encontrado", id)
                            );
                    }
                    lancamento.dataRecebimentoPagamento = dataRecebimentoPagamento;
                    lancamento.idConta = idConta;
                    lancamento.status = true;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu um erro ao tentar atualizar o lancamento", ex);
            }
        }
Example #7
0
 public static bool existeUsuario()
 {
     using (OikoDataContext db = new OikoDataContext())
     {
         if (db.Usuario.Count() > 0)
             return true;
         return false;
     }
 }
Example #8
0
 public static void add(Usuario usuario)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             db.Usuario.InsertOnSubmit(usuario);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar criar o usuario", ex);
     }
 }
 public static void add(Lancamento lancamento)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             db.Lancamento.InsertOnSubmit(lancamento);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar criar a lancamento", ex);
     }
 }
 public static void addCategoria(string nome, string tipo)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Categoria categoria = new Categoria { nome = nome, tipo = tipo };
             db.Categoria.InsertOnSubmit(categoria);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar criar a categoria", ex);
     }
 }
 public static void addFormaPagamento(string nome)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             FormaPagamento formaPagamento = new FormaPagamento { nome = nome };
             db.FormaPagamento.InsertOnSubmit(formaPagamento);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar criar a formaPagamento", ex);
     }
 }
Example #12
0
 public static void addConta(string nome, decimal saldo, bool saldoNegativo)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Conta conta = new Conta { nome = nome, saldo = saldo, saldoNegativo = saldoNegativo};
             db.Conta.InsertOnSubmit(conta);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar criar a conta", ex);
     }
 }
Example #13
0
 public static Usuario get()
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Usuario usuario = db.Usuario.First();
             if (usuario == null)
             {
                 throw new Exception(
                     string.Format("Não existe usuário cadastrado!")
                     );
             }
             return usuario;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar retornar a usuario", ex);
     }
 }
 public static FormaPagamento getFormaPagamento(int id)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             FormaPagamento formaPagamento = db.FormaPagamento.SingleOrDefault(fp => fp.id == id);
             if (formaPagamento == null)
             {
                 throw new Exception(
                     string.Format("A formaPagamento com id {0} não foi encontrada", id)
                     );
             }
             return formaPagamento;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar retornar a formaPagamento", ex);
     }
 }
Example #15
0
 public static Conta getConta(int id)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Conta conta = db.Conta.SingleOrDefault(c => c.id == id);
             if (conta == null)
             {
                 throw new Exception(
                     string.Format("A conta com id {0} não foi encontrada", id)
                     );
             }
             return conta;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar retornar a conta", ex);
     }
 }
Example #16
0
 public static void deleteConta(int id)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Conta conta = db.Conta.SingleOrDefault(c => c.id == id);
             if (conta == null)
             {
                 throw new Exception(
                     string.Format("A conta com id {0} não foi encontrada", id)
                     );
             }
             db.Conta.DeleteOnSubmit(conta);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar excluir a conta", ex);
     }
 }
Example #17
0
 public static void deleteUsuario(int id)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Usuario usuario = db.Usuario.SingleOrDefault(u => u.id == id);
             if (usuario == null)
             {
                 throw new Exception(
                     string.Format("O usuario com id {0} não foi encontrada", id)
                     );
             }
             db.Usuario.DeleteOnSubmit(usuario);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar excluir a usuario", ex);
     }
 }
 public static void delete(int id)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Lancamento lancamento = db.Lancamento.SingleOrDefault(l => l.id == id);
             if (lancamento == null)
             {
                 throw new Exception(
                     string.Format("O lancamento com id {0} não foi encontrado", id)
                     );
             }
             db.Lancamento.DeleteOnSubmit(lancamento);
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar excluir a lancamento", ex);
     }
 }
        public static void updateFormaPagamento(int id, string nome)
        {
            try
            {
                using (OikoDataContext db = new OikoDataContext())
                {
                    FormaPagamento formaPagamento = db.FormaPagamento.SingleOrDefault(fp => fp.id == id);
                    if (formaPagamento == null)
                    {
                        throw new Exception(
                            string.Format("A formaPagamento com id {0} não foi encontrada", id)
                            );
                    }
                    formaPagamento.nome = nome;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu um erro ao tentar atualizar a formaPagamento", ex);
            }
        }
Example #20
0
        public static void updateConta(int id, string nome, bool saldoNegativo)
        {
            try
            {
                using (OikoDataContext db = new OikoDataContext())
                {
                    Conta conta = db.Conta.SingleOrDefault(c => c.id == id);
                    if (conta == null)
                    {
                        throw new Exception(
                            string.Format("A conta com id {0} não foi encontrada", id)
                            );
                    }
                    conta.nome = nome;
                    conta.saldoNegativo = saldoNegativo;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu um erro ao tentar atualizar a conta", ex);
            }
        }
        public static void updateCategoria(int id, string nome, string tipo)
        {
            try
            {
                using (OikoDataContext db = new OikoDataContext())
                {
                    Categoria categoria = db.Categoria.SingleOrDefault(c => c.id == id);
                    if (categoria == null)
                    {
                        throw new Exception(
                            string.Format("A categoria com id {0} não foi encontrada", id)
                            );
                    }
                    categoria.nome = nome;
                    categoria.tipo = tipo;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu um erro ao tentar atualizar a categoria", ex);
            }
        }
        public static void update(Lancamento nl)
        {
            try
            {
                using (OikoDataContext db = new OikoDataContext())
                {
                    Lancamento lancamento = db.Lancamento.SingleOrDefault(l => l.id == nl.id);
                    if (lancamento == null)
                    {
                        throw new Exception(
                            string.Format("O lancamento com id {0} não foi encontrado", nl.id)
                            );
                    }
                    lancamento.dataLancamento = nl.dataLancamento;
                    lancamento.valor = nl.valor;
                    lancamento.descricao = nl.descricao;
                    lancamento.idCategoria = nl.idCategoria;
                    lancamento.idConta = nl.idConta;
                    lancamento.idFormaPagamento = nl.idFormaPagamento;
                    lancamento.multa = nl.multa;
                    lancamento.jurosPorDia = nl.jurosPorDia;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu um erro ao tentar atualizar o lancamento", ex);
            }
        }
 public static Lancamento get(int id)
 {
     try
     {
         using (OikoDataContext db = new OikoDataContext())
         {
             Lancamento lancamento = db.Lancamento.SingleOrDefault(l => l.id == id);
             if (lancamento == null)
             {
                 throw new Exception(
                     string.Format("O lancamento com id {0} não foi encontrada", id)
                     );
             }
             return lancamento;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Ocorreu um erro ao tentar retornar o lancamento", ex);
     }
 }
Example #24
0
        public static void updateUsuario(Usuario usuarioAtualizado)
        {
            try
            {
                using (OikoDataContext db = new OikoDataContext())
                {
                    Usuario usuario = get();

                    usuario.nome = usuarioAtualizado.nome;
                    usuario.email = usuarioAtualizado.email;
                    usuario.login = usuarioAtualizado.login;
                    usuario.senha = usuarioAtualizado.senha;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ocorreu um erro ao tentar atualizar a usuario", ex);
            }
        }