예제 #1
0
        public CommandResponse AdicionarRegra(RegrasForunsBrasil regra)
        {
            try
            {
                using (_context.Connection)
                {
                    _context.GetConnection();

                    var param = new DynamicParameters();
                    param.Add(name: "IdEstado", value: regra.IdEstado, direction: System.Data.ParameterDirection.Input);
                    param.Add(name: "IdComarca", value: regra.IdComarca, direction: System.Data.ParameterDirection.Input);

                    if (regra.IdCidade == 0)
                    {
                        param.Add(name: "IdCidade", value: null, direction: System.Data.ParameterDirection.Input);
                    }
                    else
                    {
                        param.Add(name: "IdCidade", value: regra.IdCidade, direction: System.Data.ParameterDirection.Input);
                    }

                    param.Add(name: "Regra", value: regra.Regra, direction: System.Data.ParameterDirection.Input);
                    param.Add(name: "Status", value: regra.Status, direction: System.Data.ParameterDirection.Input);

                    var t = _context.Connection.Execute(RegrasForunsQueries.InsertRegra(), param);

                    return(new CommandResponse(true, $"{regra.Regra} adicionada com sucesso"));
                }
            }
            catch (SQLiteException ex)
            {
                return(new CommandResponse(false, $"Erro : {ex.Message}"));
            }
        }
예제 #2
0
 public CommandResponse AtualizarRegraBairro(RegrasForunsBairros regra)
 {
     try
     {
         using (_context.Connection)
         {
             _context.GetConnection();
             _context.Connection.Execute(RegrasForunsQueries.UpdateRegraBairro(regra));
             return(new CommandResponse(true, $"{regra.Regra} atualizada com sucesso"));
         }
     }
     catch (SQLiteException ex)
     {
         return(new CommandResponse(false, $"Erro : {ex.Message}"));
     }
 }
예제 #3
0
 public CommandResponse AtualizarBairro(Bairro bairro)
 {
     try
     {
         using (_context.Connection)
         {
             _context.GetConnection();
             var query = RegrasForunsQueries.UpdateBairro(bairro);
             _context.Connection.Execute(query);
             return(new CommandResponse(true, $"{bairro.Descricao} atualizada com sucesso"));
         }
     }
     catch (SQLiteException ex)
     {
         return(new CommandResponse(false, $"Erro : {ex.Message}"));
     }
 }
예제 #4
0
 public CommandResponse RemoverBairro(long id)
 {
     try
     {
         using (_context.Connection)
         {
             _context.GetConnection();
             var query = RegrasForunsQueries.DeleteBairro(id);
             _context.Connection.Execute(query);
             return(new CommandResponse(true, $"Bairro removido com sucesso"));
         }
     }
     catch (SQLiteException ex)
     {
         return(new CommandResponse(false, $"Erro : {ex.Message}"));
     }
 }
예제 #5
0
 public RegrasForunsBairros ObtemRegraBairro(FiltroBairroCommand filtro)
 {
     try
     {
         using (_context.Connection)
         {
             _context.GetConnection();
             return(_context
                    .Connection
                    .Query <RegrasForunsBairros>(RegrasForunsQueries.SelectRegraBairro(filtro), new { }).FirstOrDefault());
         }
     }
     catch (SQLiteException ex)
     {
         throw ex;
     }
 }
예제 #6
0
 public CommandResponse RemoverRegraBairro(RegrasForunsBairros regra)
 {
     try
     {
         using (_context.Connection)
         {
             var t = RegrasForunsQueries.DeleteRegraBairro(regra);
             _context.GetConnection();
             _context.Connection.Execute(RegrasForunsQueries.DeleteRegraBairro(regra));
             return(new CommandResponse(true, $" Regra removida com sucesso"));
         }
     }
     catch (SQLiteException ex)
     {
         return(new CommandResponse(true, $"Erro : {ex.Message}"));
     }
 }
예제 #7
0
        public ICollection <RegrasForunsBrasil> ObterTodos()
        {
            try
            {
                using (_context.Connection)
                {
                    _context.GetConnection();

                    return(_context
                           .Connection
                           .Query <RegrasForunsBrasil>(RegrasForunsQueries.SelectAll(), new { }).ToList());
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
        }
예제 #8
0
        public CommandResponse AdicionarComarca(long idEstado, string comarca)
        {
            try
            {
                _context.GetConnection();
                var query = RegrasForunsQueries.InsertComarca();

                var param = new DynamicParameters();
                param.Add(name: "Descricao", value: comarca, direction: System.Data.ParameterDirection.Input);
                param.Add(name: "IdEstado", value: idEstado, direction: System.Data.ParameterDirection.Input);

                _context.Connection.Execute(query, param);
                return(new CommandResponse(true, $"{comarca} adicionada com sucesso"));
            }
            catch (SQLiteException ex)
            {
                return(new CommandResponse(false, $"Erro : {ex.Message}"));
            }
        }
예제 #9
0
        public IEnumerable <RegraBairroQueryResult> ObterTodasComarca()
        {
            try
            {
                var query = RegrasForunsQueries.SelectTodasComarcasDetalhado();

                using (_context.Connection)
                {
                    _context.GetConnection();
                    return(_context
                           .Connection
                           .Query <RegraBairroQueryResult>(query, new { }));
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
        }
예제 #10
0
        public IEnumerable <T> ObterTodos <T>(string nomeTabela) where T : EntidadeBase <T>
        {
            try
            {
                var query = RegrasForunsQueries.SelectGeneric(nomeTabela);

                using (_context.Connection)
                {
                    _context.GetConnection();
                    return(_context
                           .Connection
                           .Query <T>(query, new { }));
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
        }
예제 #11
0
        public CommandResponse RemoverRegra(RegrasForunsBrasil regra)
        {
            try
            {
                using (_context.Connection)
                {
                    _context.GetConnection();
                    var query = RegrasForunsQueries.DeleteRegra(regra);

                    _context.Connection.Execute(query);

                    return(new CommandResponse(true, $"{regra.Regra} removida com sucesso"));
                }
            }
            catch (SQLiteException ex)
            {
                return(new CommandResponse(false, $"Erro : {ex.Message}"));
            }
        }
예제 #12
0
        public RegraBrasilQueryResult ObterPorCidadeEComarcaDetalhado(string uf, string city, string comarca)
        {
            var query = RegrasForunsQueries.SelectRegraDetalhado(uf, city, comarca);

            try
            {
                using (_context.Connection)
                {
                    _context.GetConnection();
                    return(_context
                           .Connection
                           .Query <RegraBrasilQueryResult>(query, new { }).FirstOrDefault());
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
        }
예제 #13
0
        public RegraBairroQueryResult ObtemRegraBairroDetalhado(FiltroBairroCommand filtro)
        {
            var query = RegrasForunsQueries.SelectBairroDetalhado(filtro);

            try
            {
                using (_context.Connection)
                {
                    _context.GetConnection();
                    return(_context
                           .Connection
                           .Query <RegraBairroQueryResult>(query, new { }).FirstOrDefault());
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
        }
예제 #14
0
        public CommandResponse AtualizarCidade(Cidade cidade)
        {
            try
            {
                _context.Connection.Open();
                _context.BeginTransaction();

                _context.Connection.Execute(RegrasForunsQueries.UpdateCidade(cidade), _context.Transaction);
                _context.Connection.Execute(RegrasForunsQueries.UpdateApenasComarcaRegra(cidade.IdComarca, cidade.IdEstado, cidade.Id), _context.Transaction);
                _context.Connection.Execute(RegrasForunsQueries.UpdateApenasComarcaRegraBairro(cidade.IdComarca, cidade.IdEstado, cidade.Id), _context.Transaction);

                _context.Transaction.Commit();
                _context.Dispose();
                return(new CommandResponse(true, $"{cidade.Descricao} atualizada com sucesso"));
            }
            catch (SQLiteException ex)
            {
                _context.Transaction.Rollback();
                _context.Dispose();
                return(new CommandResponse(false, $"Erro : {ex.Message}"));
            }
        }