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); }
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> /// Add Subjects to SubjectComboboxItem and to subjectList /// </summary> private void addSubjectsToList() { using (SubjectContext sc = new SubjectContext()) { subjectList = sc.GetAllSubjects(); } foreach (Subject item in subjectList) { SubjectComboboxItem.Add(new ComboboxItemViewModel { IsSelected = (PersonData as TeacherListItemViewData).Subjects.Any(f => f.Id == item.Id), Name = item.Name, Id = item.Id }); } }
/// <summary> /// Adds subjects from the database to SubjectViewData /// </summary> private void addSubjects() { using (SubjectContext sc = new SubjectContext()) { List<Subject> allSubjects = sc.GetAllSubjects(); foreach (Subject subject in allSubjects) { if (Ssvd.Subjects.Any(p => p.Id == subject.Id)) { if (SelectedSubject != null && SelectedSubject.Id == subject.Id) { Ssvd.Subjects.Remove(SelectedSubject); } else { continue; } } Ssvd.Subjects.Add(new SubjectListItemViewData() { Id = subject.Id, Name = subject.Name, }); } } }
/// <summary> /// Adds subjects to the database and refreshes the view. /// </summary> private void AutoAddSubjects() { Subject dansk = new Subject() { Name = "Dansk" }; Subject engelsk = new Subject() { Name = "Engelsk" }; Subject matematik = new Subject() { Name = "Matematik" }; Subject biologi = new Subject() { Name = "Biologi" }; using (SubjectContext sc = new SubjectContext()) { sc.AddNewSubject(dansk); sc.AddNewSubject(engelsk); sc.AddNewSubject(matematik); sc.AddNewSubject(biologi); } canAutoAdd = false; addSubjects(); }