public Scor findOne(int id) { MySqlConnection connection = databaseConnection.getConnection(); ParticipantRepository participantRepository = new ParticipantRepository(); ProbaRepository probaRepository = new ProbaRepository(); using (connection) { connection.Open(); MySqlCommand cmd = new MySqlCommand("Select * from scores where id=@id", connection); cmd.Parameters.AddWithValue("@id", id); cmd.Prepare(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Participant participant = participantRepository.findOne(Convert.ToInt32(reader["id_participant"])); Proba proba = probaRepository.findOne(Convert.ToInt32(reader["id_proba"])); return(new Scor( Convert.ToInt32(reader["ID"]), participant, proba, Convert.ToInt32(reader["score"]) )); } } connection.Close(); } return(null); }
public List <Scor> findAll() { MySqlConnection connection = databaseConnection.getConnection(); using (connection) { connection.Open(); MySqlCommand cmd = new MySqlCommand("Select * from scores", connection); List <Scor> list = new List <Scor>(); cmd.Prepare(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Participant participant = participantRepository.findOne(Convert.ToInt32(reader["IDParticipant"])); Proba proba = probaRepository.findOne(Convert.ToInt32(reader["IDProba"])); list.Add(new Scor( Convert.ToInt32(reader["ID"]), participant, proba, Convert.ToInt32(reader["score"]))); } return(list); } } }
public Proba findOne(int id) { return(probaRepository.findOne(id)); }