Beispiel #1
0
        public Walker GetWalkerById(int id)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        SELECT *
                        FROM Walker WHERE Id = @id
                    ";

                    cmd.Parameters.AddWithValue("@id", id);

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        Walker walker = new Walker
                        {
                            Id             = reader.GetInt32(reader.GetOrdinal("Id")),
                            Name           = reader.GetString(reader.GetOrdinal("Name")),
                            ImageUrl       = ReaderUtil.GetNullableString(reader, "ImageUrl"),
                            NeighborhoodId = reader.GetInt32(reader.GetOrdinal("NeighborhoodId")),
                            Neighborhood   = _neighborhoodrepo.GetNeighborhoodById(reader.GetInt32(reader.GetOrdinal("NeighborhoodId")))
                        };

                        reader.Close();
                        return(walker);
                    }
                    else
                    {
                        reader.Close();
                        return(null);
                    }
                }
            }
        }