private static void CreateSubjects(MainViewModel mainViewModel, int year) { foreach (SubjectViewModel subject in MainViewModel.Instance.Parameters.Subjects.Where(s => s.ParentSubject == null)) { SubjectModel.Save(new SubjectViewModel() { Coefficient = subject.Coefficient, Name = subject.Name, Option = subject.Option, Order = subject.Order, Year = year, }); } mainViewModel.Parameters.LoadSubjects(); foreach (SubjectViewModel subject in MainViewModel.Instance.Parameters.Subjects.Where(s => s.ParentSubject != null)) { SubjectModel.Save(new SubjectViewModel() { Coefficient = subject.Coefficient, Name = subject.Name, Option = subject.Option, Order = subject.Order, ParentSubject = mainViewModel.Parameters.Subjects.FirstOrDefault(s => s.Name == subject.ParentSubject.Name), Year = year, }); } mainViewModel.Parameters.LoadSubjects(); }