Esempio n. 1
0
        public ProgramGroupsContract GetGroups(int id)
        {
            var programs = programRepository.GetRelated(id);

            if (programs == null)
            {
                return(null);
            }

            var currentStudyYear = studyYearRepository.GetCurrent();

            if (currentStudyYear == null)
            {
                throw new InvalidOperationException("Failed to get the current study year");
            }

            return(new ProgramGroupsContract
            {
                Id = id,
                Groups = programs
                         .SelectMany(sp => sp.ContingentUnits)
                         .Where(cu => cu is StudentGroup && !cu.IsArchived)
                         .Cast <StudentGroup>()
                         .OrderBy(sg => sg.StudyPlan?.StudyForm?.Name)
                         .ThenBy(sg => sg.Name)
                         .Where(sg => sg.CurrentStudyYear == currentStudyYear)
                         .Select(sg => new ProgramGroupsContract.Group
                {
                    Id = sg.Id,
                    Name = sg.Name,
                    Form = sg.StudyPlan?.StudyForm?.GetNameByLanguage(language) ?? string.Empty,
                    Profiles = Trim(sg.GetProfilesStringByLanguage(language), 60)
                })
            });
        }
        public IEnumerable <StudyDivisionProgramLevelContract> GetProgramLevels(string alias)
        {
            var division = divisionsRepository.Get(alias);

            if (division == null)
            {
                return(null);
            }

            var titlePreamble = division.Name.Contains(",") ?
                                Resources.Divisions :
                                Resources.Division;

            var divisionTitle    = $"{titlePreamble} {division.GetNameByLanguage(language)}";
            var currentStudyYear = studyYearRepository.GetCurrent();

            if (currentStudyYear == null)
            {
                throw new InvalidOperationException("Failed to get the current study year");
            }

            return(division
                   .StudentGroups
                   .Where(sg => sg.StudyProgram != null)
                   .Select(sg => sg.StudyProgram)
                   .Distinct()
                   .GroupBy(sp => new
            {
                ProgramName = sp.GetNameByLanguage(language),
                ProgramNameEnglish = sp.NameEnglish,
                LevelName = sp.StudyLevel.GetNameByLanguage(language),
                LevelNameEnglish = sp.StudyLevel.NameEnglish
            })
                   .Select(g => new
            {
                ProgramName = g.Key.ProgramName,
                ProgramNameEnglish = g.Key.ProgramNameEnglish,
                LevelName = g.Key.LevelName,
                LevelNameEnglish = g.Key.LevelNameEnglish,
                Programs = g.AsEnumerable()
            })
                   .GroupBy(x => new { x.LevelName, x.LevelNameEnglish })
                   .Select(g => new StudyDivisionProgramLevelContract
            {
                Name = culture.TextInfo.ToTitleCase(g.Key.LevelName.ToLower()),
                NameEnglish = g.Key.LevelNameEnglish,
                // TODO: удалить неактуальный HasCourse6
                // при выпуске новой версии API
                HasCourse6 = g.AsEnumerable()
                             .SelectMany(c => c.Programs)
                             .Select(sp => sp.AdmissionYear)
                             .Any(ay => (currentStudyYear.Number - ay.Number + 1) == 6),
                ProgramCombinations = g.AsEnumerable()
                                      .Select(c => new StudyDivisionProgramLevelContract.ProgramCombination
                {
                    Name = c.ProgramName,
                    NameEnglish = c.ProgramNameEnglish,
                    Years = c.Programs
                            .Where(sp => sp.ContingentUnits.Any(cu => cu is StudentGroup && !cu.IsArchived))
                            .GroupBy(sp => sp.AdmissionYear)
                            .Select(spg => spg.First())
                            .Select(sp => new StudyDivisionProgramLevelContract.Year
                    {
                        ProgramId = sp.Id,
                        Name = sp.AdmissionYear.Name,
                        Number = sp.AdmissionYear.Number,
                        DivisionAlias = division.Alias,
                        IsEmpty = false
                    })
                            .OrderByDescending(ay => ay.Number)
                })
                                      .OrderBy(pc => pc.Name)
            })
                   .OrderBy(c => c.Name));
        }