public void AddCourse(Course newCourse) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO courses_students (course_id, student_id) VALUES (@coursesId, @studentId);"; MySqlParameter courses_id = new MySqlParameter(); courses_id.ParameterName = "@studentId"; courses_id.Value = _id; cmd.Parameters.Add(courses_id); MySqlParameter course_id = new MySqlParameter(); course_id.ParameterName = "@coursesId"; course_id.Value = newCourse.GetId(); cmd.Parameters.Add(course_id); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public override bool Equals(System.Object otherCourse) { if (!(otherCourse is Course)) { return(false); } else { Course newCourse = (Course)otherCourse; bool idEquality = (this.GetId() == newCourse.GetId()); bool nameEq = (this.GetCourseName() == newCourse.GetCourseName()); bool numberEq = (this.GetCourseNumber() == newCourse.GetCourseNumber()); return(idEquality && nameEq && numberEq); } }
public override bool Equals(System.Object otherCourse) { if (!(otherCourse is Course)) { return(false); } else { Course newCourse = (Course)otherCourse; bool idEquality = this.GetId() == newCourse.GetId(); bool descriptionEquality = this.GetName() == newCourse.GetName(); bool NumberEquality = this.GetNumber() == newCourse.GetNumber(); // We no longer compare Students' CourseIds in a categoryEquality bool here. return(idEquality && descriptionEquality && NumberEquality); } }
public void AddCourse(Course newCourse) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO courses_students (student_id, course_id) VALUES (@CourseId, @StudentId);"; cmd.Parameters.Add(new MySqlParameter("@StudentId", _id)); cmd.Parameters.Add(new MySqlParameter("@CourseId", newCourse.GetId())); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }