Example #1
0
 static bool createStudent(Student student)
 {
     //Adds student to db
     using (var contxt = new SchoolDBEntities())
     {
         contxt.Students.Add(student);
         contxt.SaveChanges();
     }
     return true;
 }
Example #2
0
        static void Main(string[] args)
        {
            //Create student 1
            Student aaa = new Student();
            aaa.StudentName = "aaa aaa";
            aaa.StudentAddress = new StudentAddress();
            aaa.StudentAddress.Address1 = "123 aaa";
            aaa.StudentAddress.Address2 = "345 aaa";
            aaa.StudentAddress.City = "Long Beach";
            aaa.StudentAddress.State = "California";

            //Create student 2
            Student bbb = new Student();
            bbb.StudentName = "bbb bbb";
            bbb.StudentAddress = new StudentAddress();
            bbb.StudentAddress.Address1 = "123 bbb";
            bbb.StudentAddress.Address2 = "345 bbb";
            bbb.StudentAddress.City = "Long Beach";
            bbb.StudentAddress.State = "California";

            //Create the students in the db
            createStudent(aaa);
            createStudent(bbb);

            //Read all students
            Console.WriteLine(readStudents("aaa aaa"));
            Console.WriteLine(readStudents("bbb bbb"));

            //Update student 1
            updateStudent("aaa aaa","123 aaa new");

            //Read student 1
            Console.WriteLine(readStudents("aaa aaa"));

            //Delete student 1's address
            deleteStudentAddr("aaa aaa");

            //Read all students
            Console.WriteLine(readStudents("aaa aaa"));

            //Create new standards
            Standard full = new Standard();
            Standard part = new Standard();

            full.StandardName = "FT";
            full.Description = "Full-time Instructor";

            part.StandardName = "PT";
            part.Description = "Part-time Instructor";

            //Create new teachers
            Teacher teach1 = new Teacher();
            Teacher teach2 = new Teacher();
            Teacher teach3 = new Teacher();

            teach1.TeacherName = "Teacher Name 1";
            teach2.TeacherName = "Teacher Name 2";
            teach3.TeacherName = "Teacher Name 3";

            teach1.Standard = full;
            teach2.Standard = full;
            teach3.Standard = part;

            full.Teachers.Add(teach1);
            full.Teachers.Add(teach2);
            part.Teachers.Add(teach3);

            //Create the standards and teachers in the db
            createStandard(full);
            createStandard(part);

            createTeacher(teach1);
            createTeacher(teach2);
            createTeacher(teach3);

            //Read all teachers
            Console.WriteLine(readTeachers(teach1.TeacherName,1));
            Console.WriteLine(readTeachers(teach2.TeacherName, 1));
            Console.WriteLine(readTeachers(teach3.TeacherName, 1));

            //Update the full time standard
            updateStandard("FT", "Full-time Instructor Update");

            Console.WriteLine(readTeachers("FT"));

            Console.WriteLine(readTeachers(teach1.TeacherName, 1));

            updateTeachID(teach1, teach3);
            Console.WriteLine(readTeachers(teach1.TeacherName, 1));
        }