public void Update(CourseModel course)
        {
            var sql = @"
                UPDATE Courses
                SET
                    Name = @Name,
                    Department = @Department,
                    Number = @Number,
                    Section = @Section,
                    Professor = @Professor,
                    Year = @Year,
                    Semester = @Semester
                WHERE Id = @Id";

            var parameters = new[]
            {
                new SqlParameter("@Id", course.Id),
                new SqlParameter("@Name", course.Name),
                new SqlParameter("@Department", course.Department),
                new SqlParameter("@Number", course.Number),
                new SqlParameter("@Section", course.Section),
                new SqlParameter("@Professor", course.Professor),
                new SqlParameter("@Year", course.Year),
                new SqlParameter("@Semester", course.Semester)
            };

            using (var connection = GetAndOpenConnection())
            using (var command = GetCommand(sql, connection, parameters))
                command.ExecuteNonQuery();
        }
        public IEnumerable<CourseModel> FindAll()
        {
            var sql = @"SELECT * FROM Courses";
            var courses = new List<CourseModel>();

            using (var connection = GetAndOpenConnection())
            using (var command = GetCommand(sql, connection))
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var course = new CourseModel();
                    course.Department = Convert.ToString(reader["Department"]);
                    course.Id = Guid.Parse(Convert.ToString(reader["Id"]));
                    course.Name = Convert.ToString(reader["Name"]);
                    course.Number = Convert.ToInt32(reader["Number"]);
                    course.Professor = Convert.ToString(reader["Professor"]);
                    course.Section = Convert.ToChar(reader["Section"]);
                    course.Semester = Convert.ToString(reader["Semester"]);
                    course.Year = Convert.ToInt32(reader["Year"]);

                    courses.Add(course);
                }
            }

            return courses;
        }
        public void AddStudent()
        {
            var course = new CourseModel();

            controller.Add(course);
            mockCourseRepository.Verify(r => r.Add(course), Times.Once);
            mockCourseRepository.Verify(r => r.Add(It.IsAny<CourseModel>()), Times.Once);
        }
        public void AddCourse()
        {
            var newCourse = new CourseModel();
            newCourse.Id = Guid.NewGuid();
            newCourse.Name = "Add Course";
            newCourse.Department = "DEPT";
            newCourse.Number = Random.Next();
            newCourse.Professor = String.Format("Professor {0}", newCourse.Id);
            newCourse.Year = DateTime.Now.Year;
            newCourse.Semester = "SPRING";
            newCourse.Section = 'K';

            CourseRepository.Add(newCourse);

            var courses = CourseRepository.FindAll();
            var course = courses.First(c => c.Id == newCourse.Id);
            AssertCoursesAreEqual(course, newCourse);
        }
        public void Add(CourseModel course)
        {
            var sql = @"
                INSERT INTO Courses (Id, Name, Department, Number, Section, Professor, Year, Semester)
                VALUES (@Id, @Name, @Department, @Number, @Section, @Professor, @Year, @Semester)";

            var parameters = new[]
            {
                new SqlParameter("@Id", course.Id),
                new SqlParameter("@Name", course.Name),
                new SqlParameter("@Department", course.Department),
                new SqlParameter("@Number", course.Number),
                new SqlParameter("@Section", course.Section),
                new SqlParameter("@Professor", course.Professor),
                new SqlParameter("@Year", course.Year),
                new SqlParameter("@Semester", course.Semester)
            };

            using (var connection = GetAndOpenConnection())
            using (var command = GetCommand(sql, connection, parameters))
                command.ExecuteNonQuery();
        }
        private CourseModel CreateCourse()
        {
            var course = new CourseModel();
            course.Id = Guid.NewGuid();
            course.Name = String.Format("Name {0}", course.Id);
            course.Department = "DEPT";
            course.Number = Random.Next(1000, 10000);
            course.Professor = String.Format("Professor {0}", course.Id);
            course.Year = DateTime.Now.Year;
            course.Semester = "FALL";
            course.Section = 'A';

            CourseRepository.Add(course);

            return course;
        }
 public void Update(CourseModel course)
 {
     courseRepository.Update(course);
 }
 public void Add(CourseModel course)
 {
     courseRepository.Add(course);
 }
        private CourseTakenModel CreateCourseTaken(StudentModel student, CourseModel course)
        {
            var courseTaken = new CourseTakenModel
            {
                Student = new NameModel { Id = student.Id, Name = student.FirstName },
                Course = new NameModel { Id = course.Id, Name = course.Name },
                Grade = Random.Next(110)
            };

            var sql = @"
                INSERT INTO CoursesTaken (Student, Course, Grade)
                VALUES (@Student, @Course, @Grade)";

            var parameters = new[]
            {
                new SqlParameter("@Student", courseTaken.Student.Id),
                new SqlParameter("@Course", courseTaken.Course.Id),
                new SqlParameter("@Grade", courseTaken.Grade)
            };

            using (var connection = GetAndOpenConnection())
            using (var command = GetCommand(sql, connection, parameters))
                command.ExecuteNonQuery();

            return courseTaken;
        }
 public void Setup()
 {
     student = CreateStudent();
     course = CreateCourse();
 }
        private CourseModel CreateCourse()
        {
            var course = new CourseModel();
            course.Id = Guid.NewGuid();
            course.Name = String.Format("Name {0}", course.Id);
            course.Department = "DEPT";
            course.Number = Random.Next();
            course.Professor = String.Format("Professor {0}", course.Id);
            course.Year = DateTime.Now.Year;
            course.Semester = "FALL";
            course.Section = 'A';

            var sql = @"
                INSERT INTO Courses (Id, Name, Department, Number, Section, Professor, Year, Semester)
                VALUES (@Id, @Name, @Department, @Number, @Section, @Professor, @Year, @Semester)";

            var parameters = new[]
            {
                new SqlParameter("@Id", course.Id),
                new SqlParameter("@Name", course.Name),
                new SqlParameter("@Department", course.Department),
                new SqlParameter("@Number", course.Number),
                new SqlParameter("@Section", course.Section),
                new SqlParameter("@Professor", course.Professor),
                new SqlParameter("@Year", course.Year),
                new SqlParameter("@Semester", course.Semester)
            };

            using (var connection = GetAndOpenConnection())
            using (var command = GetCommand(sql, connection, parameters))
                command.ExecuteNonQuery();

            return course;
        }
 private void AssertCoursesAreEqual(CourseModel actual, CourseModel expected)
 {
     Assert.That(actual.Id, Is.EqualTo(expected.Id));
     Assert.That(actual.Department, Is.EqualTo(expected.Department));
     Assert.That(actual.Name, Is.EqualTo(expected.Name));
     Assert.That(actual.Number, Is.EqualTo(expected.Number));
     Assert.That(actual.Professor, Is.EqualTo(expected.Professor));
     Assert.That(actual.Section, Is.EqualTo(expected.Section));
     Assert.That(actual.Semester, Is.EqualTo(expected.Semester));
     Assert.That(actual.Year, Is.EqualTo(expected.Year));
 }