internal EmployeeDirectoryTeachersViewModel GetViewModel_Internal()
        {
            var viewModel = new EmployeeDirectoryTeachersViewModel();

            var eduProgramProfiles = new EduProgramProfileQuery(ModelContext).ListByEduLevels(Settings.EduLevels)
                                     .Select(epp => new EduProgramProfileViewModel(epp, viewModel))
                                     .ToList();

            if (Settings.ShowAllTeachers)
            {
                eduProgramProfiles.Add(new EduProgramProfileViewModel(
                                           new EduProgramProfileInfo {
                    EduProgramProfileID = Null.NullInteger,
                    EduProgram          = new EduProgramInfo
                    {
                        Code  = string.Empty,
                        Title = LocalizeString("NoDisciplines.Text")
                    }
                }, viewModel)
                                       );
            }

            if (eduProgramProfiles.Count > 0)
            {
                var teachers = new TeachersQuery(ModelContext).List();

                IEnumerable <IEmployee> eduProgramProfileTeachers;

                foreach (var eduProgramProfile in eduProgramProfiles)
                {
                    if (!Null.IsNull(eduProgramProfile.EduProgramProfileID))
                    {
                        eduProgramProfileTeachers = teachers
                                                    .Where(t => t.Disciplines.Any(
                                                               d => d.EduProgramProfileID == eduProgramProfile.EduProgramProfileID));
                    }
                    else
                    {
                        // get teachers w/o disciplines
                        eduProgramProfileTeachers = teachers
                                                    .Where(t => t.Disciplines.IsNullOrEmpty());
                    }

                    var indexer = new ViewModelIndexer(1);
                    eduProgramProfile.Teachers = new IndexedEnumerable <TeacherViewModel> (indexer,
                                                                                           eduProgramProfileTeachers
                                                                                           .OrderBy(t => t.LastName)
                                                                                           .ThenBy(t => t.FirstName)
                                                                                           .Select(t => new TeacherViewModel(t, eduProgramProfile, viewModel, indexer))
                                                                                           );
                }
            }

            viewModel.EduProgramProfiles = eduProgramProfiles;
            return(viewModel);
        }
Exemple #2
0
        public void Delete(int id)
        {
            var entity = new TeachersQuery().Get(id);

            SessionFactoryHelper.CurrentSession.Delete(entity);
        }