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 (@CourseId, @StudentId);";

            MySqlParameter course_id = new MySqlParameter();

            course_id.ParameterName = "@CourseId";
            course_id.Value         = newCourse.GetId();
            cmd.Parameters.Add(course_id);

            MySqlParameter student_id = new MySqlParameter();

            student_id.ParameterName = "@StudentId";
            student_id.Value         = _id;
            cmd.Parameters.Add(student_id);

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
        public void Test_Find_FindsCourseInDatabase()
        {
            //Arrange
            Course testCourse = new Course("Intro To CS");

            testCourse.Save();

            //Act
            Course foundCourse = Course.Find(testCourse.GetId());

            //Assert
            Assert.Equal(testCourse, foundCourse);
        }
 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   nameEquality = this.GetName() == newCourse.GetName();
         return(idEquality && nameEquality);
     }
 }
        public void Test_GetStudents_RetrievesAllStudentsWithCourse()
        {
            //Arrange
            Course testCourse = new Course("Intro To CS");

            testCourse.Save();
            Student firstStudent = new Student("Matt Caswell", "04/01/2017", testCourse.GetId());

            firstStudent.Save();
            Student secondStudent = new Student("Jasper", "07/24/2017", testCourse.GetId());

            secondStudent.Save();

            //Act
            testCourse.AddStudent(firstStudent);
            testCourse.AddStudent(secondStudent);
            List <Student> testStudentList = new List <Student> {
                firstStudent, secondStudent
            };
            List <Student> resultStudentList = testCourse.GetStudents();

            //Assert
            Assert.Equal(testStudentList, resultStudentList);
        }
        public void Test_Save_AssignsIdToCourseObject()
        {
            //Arrange
            Course testCourse = new Course("Intro To CS");

            testCourse.Save();

            //Act
            Course savedCourse = Course.GetAll()[0];

            int result = savedCourse.GetId();
            int testId = testCourse.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
        public void AddCourse(Course newCourse)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO students_courses (student_id, course_id) VALUES (@StudentId, @CourseId);", conn);

            cmd.Parameters.Add(new SqlParameter("@StudentId", this.GetId()));
            cmd.Parameters.Add(new SqlParameter("@CourseId", newCourse.GetId()));

            cmd.ExecuteNonQuery();

            if (conn != null)
            {
                conn.Close();
            }
        }