示例#1
0
        public void Find_ReturnsFoundStudent_name()
        {
            Student newStudent = new Student("Sally");

            newStudent.Save();

            Student foundStudent = Student.Find(newStudent.GetId());

            Assert.Equal(newStudent, foundStudent);
        }
示例#2
0
        public void Test_Find_ReturnsSameObject()
        {
            Student newStudent = new Student("John", "8-10-2009", 3);

            newStudent.Save();

            Student testStudent = Student.Find(newStudent.GetId());

            Assert.Equal(testStudent, newStudent);
        }
示例#3
0
        public void Test_FindFindsStudentInDatabase()
        {
            //Arrange
            Student firstStudent = new Student("Jerry", "03/01/2012");

            firstStudent.Save();

            //Act
            Student result = Student.Find(firstStudent.GetId());

            //Assert
            Assert.Equal(firstStudent, result);
        }
示例#4
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Department> AllDepartments = Department.GetAll();
                return(View["index.cshtml", AllDepartments]);
            };

            Post["/department/new"] = _ => {
                Department newDepartment = new Department(Request.Form["department-name"]);
                newDepartment.Save();

                List <Department> AllDepartments = Department.GetAll();
                return(View["index.cshtml", AllDepartments]);
            };

            Get["/courses"] = _ => {
                List <Course> AllCourses = Course.GetAll();
                return(View["courses.cshtml", AllCourses]);
            };

            Post["/course/new"] = _ => {
                Course newCourse = new Course(Request.Form["course-name"], Request.Form["course-number"]);
                newCourse.Save();
                List <Course> AllCourses = Course.GetAll();
                return(View["courses.cshtml", AllCourses]);
            };

            Get["/students"] = _ => {
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

            Post["/student/new"] = _ => {
                Student newStudent = new Student(Request.Form["student-name"]);
                newStudent.Save();
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

            Delete["/student/delete/{id}"] = parameters => {
                Student foundStudent = Student.Find(parameters.id);
                foundStudent.Delete();
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };
        }
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                return(View["index.cshtml"]);
            };
            Get["/add-new-student"] = _ =>
            {
                return(View["add-new-student.cshtml"]);
            };
            Post["/added-student"] = _ =>
            {
                string studentName = Request.Form["student-name"];

                Student newStudent = new Student(studentName);
                newStudent.Save();
                return(View["added-student.cshtml", studentName]);
            };
            Get["/add-new-course"] = _ =>
            {
                return(View["add-new-course.cshtml"]);
            };
            Post["/added-course"] = _ =>
            {
                string courseName   = Request.Form["course-name"];
                string courseNumber = Request.Form["course-number"];
                Course newCourse    = new Course(courseName, courseNumber);
                newCourse.Save();
                return(View["added-course.cshtml", newCourse]);
            };
            Get["/view-all-courses"] = _ =>
            {
                List <Course> allCourses = new List <Course> {
                };
                allCourses = Course.GetAll();
                return(View["view-all-courses.cshtml", allCourses]);
            };
            Get["/view-all-students"] = _ =>
            {
                List <Student> allStudents = new List <Student> {
                };
                allStudents = Student.GetAll();
                return(View["view-all-students.cshtml", allStudents]);
            };
            Get["/course/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Course         selectedCourse     = Course.Find(parameters.id);
                List <Student> CourseStudents     = selectedCourse.GetStudents();
                List <Student> allStudents        = Student.GetAll();
                model.Add("course", selectedCourse);
                model.Add("CourseStudents", CourseStudents);
                model.Add("allStudents", allStudents);
                return(View["course.cshtml", model]);
            };
            Get["/student/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Student       selectedStudent     = Student.Find(parameters.id);
                List <Course> CourseStudents      = selectedStudent.GetCourses();
                List <Course> allCourses          = Course.GetAll();
                model.Add("student", selectedStudent);
                model.Add("CourseStudents", CourseStudents);
                model.Add("allCourses", allCourses);
                return(View["student.cshtml", model]);
            };
            Post["/student/add_course"] = _ =>
            {
                Student student = Student.Find(Request.Form["student-id"]);
                Course  course  = Course.Find(Request.Form["course-id"]);
                student.AddCourse(course);
                List <Student> allStudents = new List <Student> {
                };
                allStudents = Student.GetAll();
                return(View["view-all-students.cshtml", allStudents]);
            };
            Post["/course/add_student"] = _ =>
            {
                Course  course  = Course.Find(Request.Form["course-id"]);
                Student student = Student.Find(Request.Form["student-id"]);
                course.AddStudent(student);
                List <Course> allCourses = new List <Course> {
                };
                allCourses = Course.GetAll();
                return(View["view-all-courses.cshtml", allCourses]);
            };
        }
示例#6
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/courses"] = _ => {
                List <Course> AllCourses = Course.GetAll();
                return(View["courses.cshtml", AllCourses]);
            };

            Get["/courses/new"] = _ => {
                return(View["course_new.cshtml"]);
            };

            Post["/courses/new"] = _ => {
                Course newCourse = new Course(Request.Form["course-name"], Request.Form["course-number"]);
                newCourse.Save();
                List <Course> AllCourses = Course.GetAll();
                return(View["courses.cshtml", AllCourses]);
            };

            Get["courses/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Course         SelectedCourse     = Course.Find(parameters.id);
                List <Student> CourseStudents     = SelectedCourse.GetStudents();
                List <Student> AllStudents        = Student.GetAll();
                model.Add("course", SelectedCourse);
                model.Add("courseStudents", CourseStudents);
                model.Add("allStudents", AllStudents);
                return(View["course.cshtml", model]);
            };

            Post["course/add_student"] = _ => {
                Student student = Student.Find(Request.Form["student-id"]);
                Course  course  = Course.Find(Request.Form["course-id"]);
                course.AddStudent(student);
                return(View["success.cshtml"]);
            };
// for students
            Get["/students"] = _ => {
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

            Get["/students/new"] = _ => {
                return(View["student_new.cshtml"]);
            };

            Post["/students/new"] = _ => {
                Student newStudent = new Student(Request.Form["student-name"], Request.Form["student-date"]);
                newStudent.Save();
                List <Student> AllStudents = Student.GetAll();
                return(View["students.cshtml", AllStudents]);
            };

            Get["students/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Student       SelectedStudent     = Student.Find(parameters.id);
                List <Course> StudentCourses      = SelectedStudent.GetCourses();
                List <Course> AllCourses          = Course.GetAll();
                model.Add("student", SelectedStudent);
                model.Add("studentCourses", StudentCourses);
                model.Add("allCourses", AllCourses);
                return(View["student.cshtml", model]);
            };

            Post["student/add_course"] = _ => {
                Course  course  = Course.Find(Request.Form["course-id"]);
                Student student = Student.Find(Request.Form["student-id"]);
                student.AddCourse(course);
                return(View["success.cshtml"]);
            };

// for department
            Get["/departments"] = _ => {
                List <Department> AllDepartments = Department.GetAll();
                return(View["departments.cshtml", AllDepartments]);
            };

            Get["/departments/new"] = _ => {
                return(View["department_new.cshtml"]);
            };

            Post["/departments/new"] = _ => {
                Department newDepartment = new Department(Request.Form["department-name"]);
                newDepartment.Save();
                List <Department> AllDepartments = Department.GetAll();
                return(View["departments.cshtml", AllDepartments]);
            };

            Get["departments/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Department     SelectedDepartment = Department.Find(parameters.id);
                List <Student> DepartmentStudents = SelectedDepartment.GetStudents();
                List <Student> AllStudents        = Student.GetAll();
                List <Course>  DepartmentCourses  = SelectedDepartment.GetCourses();
                List <Course>  AllCourses         = Course.GetAll();
                model.Add("department", SelectedDepartment);
                model.Add("departmentStudents", DepartmentStudents);
                model.Add("allStudents", AllStudents);
                model.Add("departmentCourses", DepartmentCourses);
                model.Add("allCourses", AllCourses);
                return(View["department.cshtml", model]);
            };

            Post["department/add_course"] = _ => {
                Course     course     = Course.Find(Request.Form["course-id"]);
                Department department = Department.Find(Request.Form["department-id"]);
                department.AddCourse(course);
                return(View["success.cshtml"]);
            };

            Post["department/add_student"] = _ => {
                Student    student    = Student.Find(Request.Form["student-id"]);
                Department department = Department.Find(Request.Form["department-id"]);
                department.AddStudent(student);
                return(View["success.cshtml"]);
            };
        }
示例#7
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/students"] = _ => {
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

            Get["/students/new"] = _ => {
                return(View["new_student.cshtml"]);
            };

            Post["/students"] = _ => {
                Student newStudent = new Student(Request.Form["student-name"], DateTime.Now);
                newStudent.Save();
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

            Get["/courses"] = _ => {
                List <Course> allCourses = Course.GetAll();
                return(View["courses.cshtml", allCourses]);
            };

            Get["/courses/new"] = _ => {
                return(View["new_course.cshtml"]);
            };

            Post["/courses"] = _ => {
                Course newCourse = new Course(Request.Form["course-name"], Request.Form["course-number"]);
                newCourse.Save();
                List <Course> allCourses = Course.GetAll();
                return(View["courses.cshtml", allCourses]);
            };

            Get["/courses/{courseId}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Course         selectedCourse     = Course.Find(parameters.courseId);
                List <Student> students           = selectedCourse.GetStudents();
                List <Student> allStudents        = Student.GetAll();
                model.Add("selected-course", selectedCourse);
                model.Add("students", students);
                model.Add("all-students", allStudents);
                return(View["course.cshtml", model]);
            };

            Get["/students/{studentId}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Student       selectedStudent     = Student.Find(parameters.studentId);
                List <Course> courses             = selectedStudent.GetCourses();
                List <Course> allCourses          = Course.GetAll();
                model.Add("selected-student", selectedStudent);
                model.Add("courses", courses);
                model.Add("all-courses", allCourses);
                return(View["student.cshtml", model]);
            };

            Post["/courses/{courseId}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Course selectedCourse             = Course.Find(parameters.courseId);
                selectedCourse.AddStudent(Student.Find(Request.Form["selected-student"]));
                List <Student> students    = selectedCourse.GetStudents();
                List <Student> allStudents = Student.GetAll();
                model.Add("selected-course", selectedCourse);
                model.Add("students", students);
                model.Add("all-students", allStudents);
                return(View["course.cshtml", model]);
            };

            Delete["/students/{student_id}/delete"] = parameters => {
                Student foundStudent = Student.Find(parameters.student_id);
                foundStudent.Delete();
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

            Delete["/courses"] = _ => {
                Course.DeleteAll();
                List <Course> allCourses = Course.GetAll();
                return(View["courses.cshtml", allCourses]);
            };

            Delete["/students"] = _ => {
                Student.DeleteAll();
                List <Student> allStudents = Student.GetAll();
                return(View["students.cshtml", allStudents]);
            };

            Get["/courses/results"] = _ => {
                List <Course> matches = Course.Search(Request.Form["search"]);
                return(View["results.cshtml", matches]);
            };
        }