using System; using System.Collections.Generic; using Microsoft.Extensions.Options; using MySqlConnector; namespace Policlinica.DB; public class DoctorRepository { MySqlConnection connection; public DoctorRepository(IOptions connect) { connection = new MySqlConnection(connect.Value.ConnectionString); } public List GetDoctorsByTest() { List result = new List(); string sql = "select * from doctors"; try { connection.Open(); using (var mc = new MySqlCommand(sql, connection)) using (var dr = mc.ExecuteReader()) { while (dr.Read()) { result.Add(new Doctor { Id = dr.GetInt32("id"), Title = dr.GetString("title"), Description = dr.GetString("description"), }); } } connection.Close(); } catch (MySqlException ex) { Console.WriteLine(ex); } catch (Exception e) { Console.WriteLine(e); } return result; } }