public void DeleteTutor(Tutor newTutor) { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"DELETE FROM tutors_clients WHERE tutor_id = @tutorId AND client_id = @clientId;"; cmd.Parameters.AddWithValue("@tutorId", newTutor.Id); cmd.Parameters.AddWithValue("@clientId", this.Id); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public void AddTutor(Tutor newTutor) { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO tutors_clients (tutor_id, client_id) VALUES (@tutorId, @clientId);"; cmd.Parameters.AddWithValue("@tutorId", newTutor.Id); cmd.Parameters.AddWithValue("@clientId", this.Id); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public static Tutor Find(int id) { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM tutors WHERE id = @tutorId;"; cmd.Parameters.AddWithValue("@tutorId", id); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; int tutorId = 0; string tutorFirstName = ""; string tutorLastName = ""; string tutorEmail = ""; string tutorPhoneNumber = ""; int tutorExperience = 0; bool tutorCredential = true; string tutorAvailability = ""; double tutorRate = 0.00; while (rdr.Read()) { tutorId = rdr.GetInt32(0); tutorFirstName = rdr.GetString(1); tutorLastName = rdr.GetString(2); tutorEmail = rdr.GetString(3); tutorPhoneNumber = rdr.GetString(4); tutorExperience = rdr.GetInt32(5); tutorCredential = rdr.GetBoolean(6); tutorAvailability = rdr.GetString(7); tutorRate = rdr.GetDouble(8); } Tutor foundTutor = new Tutor(tutorFirstName, tutorLastName, tutorEmail, tutorPhoneNumber, tutorExperience, tutorCredential, tutorAvailability, tutorRate, tutorId); conn.Close(); if (conn != null) { conn.Close(); } return(foundTutor); }
public override bool Equals(System.Object otherTutor) { if (!(otherTutor is Tutor)) { return(false); } else { Tutor newTutor = (Tutor)otherTutor; bool idEquality = (this.Id == newTutor.Id); bool firstNameEquality = (this.FirstName == newTutor.FirstName); bool lastNameEquality = (this.LastName == newTutor.LastName); bool emailEquality = (this.Email == newTutor.Email); bool phoneNumberEquality = (this.PhoneNumber == newTutor.PhoneNumber); bool experienceEquality = (this.Experience == newTutor.Experience); bool credentialEquality = (this.Credential == newTutor.Credential); bool availabilityEquality = (this.Availability == newTutor.Availability); bool rateEquality = (this.Rate == newTutor.Rate); return(idEquality && firstNameEquality && lastNameEquality && emailEquality && phoneNumberEquality && experienceEquality && credentialEquality && availabilityEquality && rateEquality); } }
public List <Tutor> GetTutors() { List <Tutor> allClientTutors = new List <Tutor> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT tutors.* FROM clients JOIN tutors_clients ON (clients.id = tutors_clients.client_id) JOIN tutors ON (tutors_clients.tutor_id = tutors.id) WHERE clients.id = @clientId;"; cmd.Parameters.AddWithValue("clientId", this.Id); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int tutorId = rdr.GetInt32(0); string tutorFirstName = rdr.GetString(1); string tutorLastName = rdr.GetString(2); string tutorEmail = rdr.GetString(3); string tutorPhoneNumber = rdr.GetString(4); int tutorExperience = rdr.GetInt32(5); bool tutorCredential = rdr.GetBoolean(6); string tutorAvailability = rdr.GetString(7); double tutorRate = rdr.GetDouble(8); Tutor newTutor = new Tutor(tutorFirstName, tutorLastName, tutorEmail, tutorPhoneNumber, tutorExperience, tutorCredential, tutorAvailability, tutorRate, tutorId); allClientTutors.Add(newTutor); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allClientTutors); }