Example #1
0
        public static CargoModel RecuperarPeloId(int id)
        {
            CargoModel ret = null;

            using (var conexao = new NpgsqlConnection())
            {
                conexao.ConnectionString = ConfigurationManager.ConnectionStrings["principal"].ConnectionString;
                conexao.Open();

                using (var comando = new NpgsqlCommand())
                {
                    comando.Connection  = conexao;
                    comando.CommandText = "select * from cargo_funcao where (id =@id)";

                    comando.Parameters.Add("@id", NpgsqlDbType.Integer).Value = id;
                    var reader = comando.ExecuteReader();

                    if (reader.Read())
                    {
                        ret = new CargoModel
                        {
                            Id    = (int)reader["id"],
                            Cargo = (string)reader["cargo"],
                        };
                    }
                }
            }
            return(ret);
        }
Example #2
0
        private bool IncluirRegistro(CargoModel model, NpgsqlConnection conexao)
        {
            var queryResult = $@"insert into cargo_funcao (cargo) values (@Cargo)";

            using (var comando = new NpgsqlCommand(queryResult, conexao))
            {
                if (model == null)
                {
                    comando.Parameters.AddWithValue("Cargo", NpgsqlDbType.Varchar, this.Cargo);
                    comando.Prepare();

                    comando.ExecuteNonQuery();
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        private bool Update(CargoModel model, NpgsqlConnection conexao)
        {
            var queryResult = $@"update cargo_funcao
                                        set cargo = @Cargo 
                                        where 
                                        id = @Id";

            using (var comando = new NpgsqlCommand(queryResult, conexao))
            {
                comando.Parameters.AddWithValue("Cargo", NpgsqlDbType.Varchar, model.Cargo);
                comando.Parameters.AddWithValue("Id", NpgsqlDbType.Integer, model.Id);
                comando.Prepare();

                if (comando.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }