/// <summary> /// Adds a new class to the database. /// </summary> /// <param name="newClass">Class object containing the new classes data.</param> /// <returns>True if success.</returns> public bool AddNewClass(Class newClass) { Class insertedClass = Context.Classes.Add(newClass); Context.SaveChanges(); if (insertedClass.Id > 0) { return true; } return false; }
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); } }
public ClassCRUDViewModel(DataContext context) { SelectedTemplate = new ClassTemplate(); SelectedClass = new Class(); this._context = context; }
public void DeleteClass() { //remove from db _context.Classes.Remove(SelectedClass); _context.SaveChanges(); //remove from ObservableCollection Classes.Remove(SelectedClass); SelectedClass = new Class(); }
public void CreateNewClass() { SelectedClass = new Class(); }
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); }