예제 #1
0
        private static void SelectedSubjectChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UtilsViewModel utils = (UtilsViewModel)d;

            utils.Teachers.Clear();
            if (utils.SelectedClass != null)
            {
                if (utils.SelectedSubject != null)
                {
                    foreach (TeacherViewModel teacher in MainViewModel.Instance.Parameters.Teachers.Where(t => t.Classes.Any(c => c.Id == utils.SelectedClass.Id) &&
                                                                                                          t.Subjects.Any(s => s.Id == (utils.SelectedSubject?.ParentSubject?.Id ?? utils.SelectedSubject.Id))))
                    {
                        utils.Teachers.Add(teacher);
                    }
                }
                int idTeacher = MarkModel.Read(MainViewModel.Instance.SelectedYear, utils.SelectedPeriod.Id).FirstOrDefault(m => m.IdClass == utils.SelectedClass.Id && m.IdSubject == utils.SelectedSubject.Id)?.IdTeacher ?? 0;
                if (idTeacher != 0)
                {
                    utils.SelectedTeacher = MainViewModel.Instance.Parameters.Teachers.FirstOrDefault(t => t.Id == idTeacher);
                }
                else
                {
                    utils.SelectedTeacher = utils.Teachers.FirstOrDefault();
                }
                utils.NbMarks       = MarkModel.Read(MainViewModel.Instance.SelectedYear, utils.SelectedPeriod.Id).Count(m => m.IdClass == utils.SelectedClass.Id && m.IdSubject == utils.SelectedSubject.Id);
                utils.ActualTeacher = utils.SelectedTeacher;
            }
        }
예제 #2
0
        private static void SelectedClassChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UtilsViewModel utils = (UtilsViewModel)d;

            utils.Subjects.Clear();
            if (utils.SelectedClass != null)
            {
                foreach (int idSubject in MarkModel.Read(MainViewModel.Instance.SelectedYear, utils.SelectedPeriod.Id).Where(m => m.IdClass == utils.SelectedClass.Id).Select(m => m.IdSubject).Distinct())
                {
                    utils.Subjects.Add(MainViewModel.Instance.Parameters.Subjects.FirstOrDefault(s => s.Id == idSubject));
                }
            }
            utils.SelectedSubject = utils.Subjects.FirstOrDefault();
        }