using System; using System.Collections.Generic; using Microsoft.Extensions.Options; using MySqlConnector; namespace Policlinica.DB; public class ServiceRepository : BaseRep { public ServiceRepository(IOptions dataBaseConnection) : base(dataBaseConnection) { OpenConnection(); } public List GetServicesByDoctor(Doctor doctor) { List result = new List(); string sql = "select * from services"; try { using (var mc = new MySqlCommand(sql, connection)) using (var dr = mc.ExecuteReader()) { while (dr.Read()) { result.Add(new Service { Id = dr.GetInt32("id"), DoctorId = dr.GetInt32("doctor_id"), ServiceName = dr.GetString("service_name"), Price = dr.GetDecimal("price"), }); } } } catch (MySqlException ex) { Console.WriteLine(ex); } catch (Exception e) { Console.WriteLine(e); } return result; } public List GetServicesByDoctors(int id) { List s = new List(); string sql = "select * from services where doctor_id =@id"; try { using (var mc = new MySqlCommand(sql, connection)) { mc.Parameters.AddWithValue("@id", id); using (var dr = mc.ExecuteReader()) { while (dr.Read()) { s.Add(new Service() { Id = dr.GetInt32("id"), DoctorId = dr.GetInt32("doctor_id"), ServiceName = dr.GetString("service_name"), Price = dr.GetDecimal("price"), }); } } } } catch (MySqlException ex) { Console.WriteLine(ex); } catch (Exception e) { Console.WriteLine(e); } return s; } public List GetServicesByTest() { List result = new List(); string sql = "select * from services"; try { using (var mc = new MySqlCommand(sql, connection)) using (var dr = mc.ExecuteReader()) { while (dr.Read()) { result.Add(new Service { Id = dr.GetInt32("id"), DoctorId = dr.GetInt32("doctor_id"), ServiceName = dr.GetString("service_name"), Price = dr.GetDecimal("price"), }); } } } catch (MySqlException ex) { Console.WriteLine(ex); } catch (Exception e) { Console.WriteLine(e); } return result; } public void Dispose() { base.Dispose(); CloseConnection(); } }