예제 #1
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]);
            };
        }
예제 #2
0
        public void Delete_DeletesIndividualStudent_list()
        {
            Student newStudent1 = new Student("Sally");

            newStudent1.Save();
            Student newStudent2 = new Student("Gretel");

            newStudent2.Save();

            newStudent2.Delete();

            List <Student> expected = new List <Student> {
                newStudent1
            };
            List <Student> actual = Student.GetAll();

            Assert.Equal(expected, actual);
        }
예제 #3
0
        public void Test_Delete_DeleteSingleStudent()
        {
            //Arrange
            Student testInput = new Student("John", "8-10-2009", 3);

            testInput.Save();
            Student testInput2 = new Student("Jose", "8-10-2009", 3);

            testInput2.Save();

            //Act
            testInput.Delete();
            List <Student> result     = Student.GetAll();
            List <Student> resultList = new List <Student> {
                testInput2
            };

            Assert.Equal(result, resultList);
        }
예제 #4
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]);
            };
        }