示例#1
0
        public async Task <Genero> PegarIdAsync(int id)
        {
            //Criando o Id do genero
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @$ "SELECT Id, Descricao
                                    FROM Genero 
                                    WHERE Id= {id}";


                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd
                                 .ExecuteReaderAsync()
                                 .ConfigureAwait(false);

                    while (reader.Read())
                    {
                        var genero = new Genero(reader["Descricao"].ToString());

                        genero.SetId(int.Parse(reader["id"].ToString()));


                        return(genero);
                    }

                    return(default);
示例#2
0
        public async Task <Genero> GetByIdAsync(int id)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var SqlCmd = @$ "SELECT Id, Descricao
                                FROM
                                      Genero g ON g.Id = u.GeneroId
                                WHERE
                                       u.Id= '{id}'";
                using (var cmd = new SqlCommand(SqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);

                    while (reader.Read())
                    {
                        var genero = new Genero(reader["Descricao"].ToString());
                        genero.SetId(int.Parse(reader["Id"].ToString()));

                        return(genero);
                    }
                }

                return(default);