public override bool Equals(System.Object otherStudent) { if (!(otherStudent is Student)) { return(false); } else { Student newStudent = (Student)otherStudent; bool idEquality = (this.GetId() == newStudent.GetId()); bool firstNameEq = (this.GetFirstName() == newStudent.GetFirstName()); bool lastNameEq = (this.GetLastName() == newStudent.GetLastName()); bool dateOfEnrollmentEq = (this.GetDateOfEnrollment() == newStudent.GetDateOfEnrollment()); return(idEquality && firstNameEq && lastNameEq && dateOfEnrollmentEq); } }
public override bool Equals(System.Object otherStudent) { if (!(otherStudent is Student)) { return(false); } else { Student newStudent = (Student)otherStudent; bool idEquality = this.GetId() == newStudent.GetId(); bool descriptionEquality = this.GetName() == newStudent.GetName(); bool enrollDateEquality = this.GetEnrollDate() == newStudent.GetEnrollDate(); // We no longer compare Students' categoryIds in a categoryEquality bool here. return(idEquality && descriptionEquality && enrollDateEquality); } }
public override bool Equals(System.Object otherStudent) { if (!(otherStudent is Student)) { return(false); } else { Student newStudent = (Student)otherStudent; bool firstNameEquality = (this.GetFirstName() == newStudent.GetFirstName()); bool lastNameEquality = (this.GetLastName() == newStudent.GetLastName()); bool rawDateEquality = (this.GetDate() == newStudent.GetDate()); bool idEquality = (this.GetId() == newStudent.GetId()); return(firstNameEquality && lastNameEquality && rawDateEquality && idEquality); } }
public void AddStudent(Student newStudent) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO courses_students (course_id, student_id) VALUES (@CourseId, @StudentId);"; cmd.Parameters.Add(new MySqlParameter("@CourseId", _id)); cmd.Parameters.Add(new MySqlParameter("@StudentId", newStudent.GetId())); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public List <Course> GetCourses(Student student) { List <Course> allCourses = new List <Course> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT courses.* FROM courses JOIN courses_students ON (courses.id = courses_students.course_id) JOIN students ON (courses_students.student_id = students.id) WHERE student_id = @StudentId"; MySqlParameter courseIdParameter = new MySqlParameter(); courseIdParameter.ParameterName = "@StudentId"; courseIdParameter.Value = student.GetId(); cmd.Parameters.Add(courseIdParameter); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; List <Course> students = new List <Course> { }; while (rdr.Read()) { int courseId = rdr.GetInt32(0); string courseName = rdr.GetString(1); string courseNumber = rdr.GetString(2); Course newCourse = new Course(courseName, courseNumber, courseId); allCourses.Add(newCourse); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allCourses); }
public void AddStudentToCourse(Student theStudent) { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO `registration` (`student_id`, `course_id`) VALUES ('" + theStudent.GetId() + "'," + _id + ");"; cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }