Esempio n. 1
0
 static bool createTeacher(Teacher teach)
 {
     //Add teacher to db
     using (var contxt = new SchoolDBEntities())
     {
         contxt.Teachers.Add(teach);
         contxt.SaveChanges();
     }
     return true;
 }
Esempio n. 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));
        }
Esempio n. 3
0
        static bool updateTeachIDDisconnect(Teacher toChange, Teacher changeTo)
        {
            //Change standard description based on what is passed in
            //Disconnected mode
            Teacher toUpdate;
            Teacher change;
            using (var contxt = new SchoolDBEntities())
            {
                toUpdate = contxt.Teachers.Where(st => st.TeacherName == toChange.TeacherName).FirstOrDefault<Teacher>();
                change = contxt.Teachers.Where(st => st.TeacherName == changeTo.TeacherName).FirstOrDefault<Teacher>();
            }

            if (toUpdate != null && change != null)
            {
                toUpdate.StandardId = change.StandardId;
            }
            else
            {
                return false;
            }

            using (var contxt1 = new SchoolDBEntities())
            {
                contxt1.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
                contxt1.SaveChanges();
            }
            return true;
        }
Esempio n. 4
0
        static bool updateTeachID(Teacher toChange, Teacher changeTo)
        {
            //Change standard description based on what is passed in
            var contxt = new SchoolDBEntities();
            Teacher toUpdate;
            Teacher change;

            toUpdate = contxt.Teachers.Where(st => st.TeacherName== toChange.TeacherName).FirstOrDefault<Teacher>();
            change = contxt.Teachers.Where(st => st.TeacherName == changeTo.TeacherName).FirstOrDefault<Teacher>();

            if (toUpdate != null)
            {
                toUpdate.StandardId = change.StandardId;
            }
            else
            {
                return false;
            }
            contxt.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified;
            contxt.SaveChanges();

            return true;
        }