Esempio n. 1
0
 public void getTeachersFromDb()
 {
     List<Teacher> allTeachers;
     using (var tc = new TeacherContext())
     {
         allTeachers = tc.GetAllTeachers();
     }
     Assert.IsNotNull(allTeachers);
 }
Esempio n. 2
0
 public static void Cleanup()
 {
     using (var tc = new TeacherContext())
     {
         if(tc.Database.Exists())
         {
             tc.Database.Delete();
         }
     }
 }
Esempio n. 3
0
 public void getTeacherFromDbByName()
 {
     string name = "Fornavn";
     Teacher searchedTeacher;
     using (var tc = new TeacherContext())
     {
         searchedTeacher = tc.GetTeacher(name);
     }
     Assert.IsNotNull(searchedTeacher);
 }
Esempio n. 4
0
 public void getTeacherFromDb()
 {
     int id = 1;
     Teacher searchedTeacher;
     using (var tc = new TeacherContext())
     {
         searchedTeacher = tc.GetTeacher(id);
     }
     Assert.IsNotNull(searchedTeacher.Id);
 }
Esempio n. 5
0
 public void AddNewTeacherToDb()
 {
     bool success = false;
     Teacher newTeacher = new Teacher()
     {
         FirstName = "Fornavn",
         LastName = "Efternavn",
         SocialSecurityNumber = 010170,
         Address = "Hallovej 123",
         ZipCode = 1234,
         City = "Randers ikke"
     };
     using (var tc = new TeacherContext())
     {
         success = tc.AddNewTeacher(newTeacher);
     }
     Assert.IsTrue(success);
 }
Esempio n. 6
0
        public static void Startup(TestContext testcontext)
        {
            Subject subject1 = new Subject() { Name = "Init subject" };
            Subject subject2 = new Subject() { Name = "Init subject2" };
            using (var sc = new SubjectContext())
            {
                sc.AddNewSubject(subject1);
                sc.AddNewSubject(subject2);
            }

            Class class1 = new Class() { Name = "Init class" };
            Class class2 = new Class() { Name = "Init class2" };
            using (var cc = new ClassContext())
            {
                cc.AddNewClass(class1);
                cc.AddNewClass(class2);
            }

            ICollection<Subject> subjects = new ObservableCollection<Subject>();
            ICollection<Class> classes = new ObservableCollection<Class>();

            subjects.Add(subject1);
            subjects.Add(subject2);

            classes.Add(class1);
            classes.Add(class2);

            Teacher newTeacher = new Teacher()
            {
                FirstName = "Ja",
                LastName = "Hallo",
                SocialSecurityNumber = 010203,
                Address = "Hallovej 123",
                ZipCode = 5678,
                City = "Viborg",
                Subjects = subjects,
                Classes = classes
            };
            using (var tc = new TeacherContext())
            {
                tc.AddNewTeacher(newTeacher);
            }
        }
        /// <summary>
        /// The method the command use to save a Teacher
        /// </summary>
        /// <param name="sender">The EditTeacher window</param>
        private void SaveTeacher(EditTeacher sender)
        {
            TeacherListItemViewData teacherData = (TeacherListItemViewData)PersonData;
                            bool isSaved = false;
            EditTeacher et = sender;
            ICollection<Subject> teacherSubjects = new ObservableCollection<Subject>();

            Teacher teacherModel = new Teacher
            {
                Id = teacherData.Id,
                SocialSecurityNumber = teacherData.SocialSecurityNumber,
                FirstName = teacherData.FirstName,
                LastName = teacherData.LastName,
                Address = teacherData.Address,
                City = teacherData.City,
                ZipCode = teacherData.ZipCode
            };
            foreach (ComboboxItemViewModel item in subjectComboboxItem)
            {
                if (item.IsSelected)
                {
                    teacherModel.Subjects.Add(subjectList.Where(f => f.Id == item.Id).FirstOrDefault());
                }
            }
            foreach (ComboboxItemViewModel item in ClassComboboxItem)
            {
                if (item.IsSelected)
                {
                    teacherModel.Classes.Add(classList.Where(f => f.Id == item.Id).FirstOrDefault());
                }
            }

            using (TeacherContext tc = new TeacherContext())
            {

                if (isEdit)
                {
                    isSaved = tc.EditTeacher(teacherModel);
                }
                else
                {
                    isSaved = tc.AddNewTeacher(teacherModel);
                }
                if (isSaved)
                {
                    et.DialogResult = true;
                    et.Close();
                }
                ErrorMsg = "Teacher did not work";
            }
        }
Esempio n. 8
0
        public void AddNewTeacherClassesAndSubjectsToDb()
        {
            bool success = false;

            Subject subject1 = new Subject() { Name = "Test subject" };
            Subject subject2 = new Subject() { Name = "Test subject2" };
            using (var sc = new SubjectContext())
            {
                sc.AddNewSubject(subject1);
                sc.AddNewSubject(subject2);
            }

            Class class1 = new Class() { Name = "Test class" };
            Class class2 = new Class() { Name = "Test class2" };
            using (var cc = new ClassContext())
            {
                cc.AddNewClass(class1);
                cc.AddNewClass(class2);
            }

            ICollection<Subject> subjects = new ObservableCollection<Subject>();
            ICollection<Class> classes = new ObservableCollection<Class>();

            subjects.Add(subject1);
            subjects.Add(subject2);

            classes.Add(class1);
            classes.Add(class2);

            Teacher newTeacher = new Teacher()
            {
                FirstName = "Fornavn",
                LastName = "Efternavn",
                SocialSecurityNumber = 010170,
                Address = "Hallovej 123",
                ZipCode = 1234,
                City = "Randers ikke",
                Subjects = subjects,
                Classes = classes
            };
            using (var tc = new TeacherContext())
            {
                success = tc.AddNewTeacher(newTeacher);
            }
            Assert.IsTrue(success);
        }
Esempio n. 9
0
 public void getTeacherFromDbAndEditIt()
 {
     int id = 1;
     bool didWeEdit = false;
     Teacher searchedTeacher;
     using (var tc = new TeacherContext())
     {
         searchedTeacher = tc.GetTeacher(id);
         searchedTeacher.FirstName = "New Name";
         didWeEdit = tc.EditTeacher(searchedTeacher);
     }
     Assert.IsTrue(didWeEdit);
 }
Esempio n. 10
0
 public TeacherController(TeacherContext teacherContext)
 {
     TeacherContext = teacherContext;
 }
 /// <summary>
 /// add all teacher to the person list
 /// </summary>
 private void addTeachersToPersons()
 {
     using (TeacherContext tc = new TeacherContext())
     {
         List<Teacher> allTeachers = tc.GetAllTeachers();
         foreach (Teacher teacher in allTeachers)
         {
             if (Person.Persons.Any(p => p.Id == teacher.Id))
             {
                 if (SelectedPerson != null && SelectedPerson.Id == teacher.Id)
                 {
                     Person.Persons.Remove(SelectedPerson);
                 }
                 else
                 {
                     continue;
                 }
             }
             ObservableCollection<Subject> teachersSubjects = new ObservableCollection<Subject>();
             foreach (var item in teacher.Subjects)
             {
                 teachersSubjects.Add(item);
             }
             ObservableCollection<Class> teachersClasses = new ObservableCollection<Class>();
             foreach (var item in teacher.Classes)
             {
                 teachersClasses.Add(item);
             }
             Person.Persons.Add(new TeacherListItemViewData()
             {
                 Id = teacher.Id,
                 FirstName = teacher.FirstName,
                 LastName = teacher.LastName,
                 Address = teacher.Address,
                 City = teacher.City,
                 SocialSecurityNumber = teacher.SocialSecurityNumber,
                 ZipCode = teacher.ZipCode,
                 Subjects = teachersSubjects,
                 Classes = teachersClasses
             });
         }
     }
 }