Beispiel #1
0
 public static IEnumerable <StudyEventAggregatedDayItemViewModel> GetEducatorAggregatedEventsDays(
     EducatorMasterPerson educatorMasterPerson, DateTime fromDate, DateTime toDate)
 {
     using (var appointmentsRepository = new EducatorAppointmentsRepository(educatorMasterPerson, educatorMasterPerson.Persons.SelectMany(p => p.EducatorEmployments), fromDate, toDate))
     {
         return(GetStudyEventAggregatedDayItemViewModels(appointmentsRepository, forEducator: educatorMasterPerson));
     }
 }
Beispiel #2
0
 private static IEnumerable <StudyEventItemViewModel> GetEducatorEvents(
     EducatorMasterPerson educatorMasterPerson, DateTime fromDate, DateTime toDate)
 {
     using (var appointmentsRepository = new EducatorAppointmentsRepository(educatorMasterPerson.Persons.SelectMany(p => p.EducatorEmployments), fromDate, toDate))
     {
         var appointments = appointmentsRepository.GetAppointments();
         return(appointments
                .Where(a => a.IsPublicMaster)
                .OrderBy(a => a.Start)
                .ThenBy(a => a.SubjectEnglish)
                .Select(a => StudyEventItemViewModel.Build(a, forEducator: educatorMasterPerson)));
     }
 }
Beispiel #3
0
        public EducatorEventsContract GetEvents(int educatorId, int?showNextTerm)
        {
            var educator = educatorRepository.Get(educatorId);

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

            var employments             = educator.Persons.SelectMany(p => p.EducatorEmployments);
            var educatorDisplayText     = educator.GetDisplayNameByLanguage(language);
            var educatorLongDisplayText = educator.GetLongDisplayNameByLanguage(language);
            var now = DateTime.Now;
            var summerTermBoundary     = new DateTime(now.Month == 1 ? now.Year - 1 : now.Year, 8, 1);
            var winterTermBoundary     = new DateTime(now >= summerTermBoundary && now.Month > 1 ? now.Year + 1 : now.Year, 2, 1);
            var nextSummerTermBoundary = new DateTime(summerTermBoundary.Year + 1, summerTermBoundary.Month, summerTermBoundary.Day);
            var nextWinterTermBoundary = new DateTime(winterTermBoundary.Year + 1, winterTermBoundary.Month, winterTermBoundary.Day);
            var isSpringTerm           = winterTermBoundary < now && now < summerTermBoundary;
            var showNext = showNextTerm.HasValue && showNextTerm.Value > 0;
            var fromDate = showNext ?
                           (isSpringTerm ? summerTermBoundary : winterTermBoundary) :
                           (isSpringTerm ? winterTermBoundary : summerTermBoundary);
            var toDate = showNext ?
                         (isSpringTerm ? nextWinterTermBoundary : nextSummerTermBoundary) :
                         (isSpringTerm ? summerTermBoundary : winterTermBoundary);
            var title = $"{Resources.TimetableForEducator} {educatorLongDisplayText}";

            DayOfWeek[] daysOfWeek =
            {
                DayOfWeek.Monday,
                DayOfWeek.Tuesday,
                DayOfWeek.Wednesday,
                DayOfWeek.Thursday,
                DayOfWeek.Friday,
                DayOfWeek.Saturday
            };

            using (var repository = new EducatorAppointmentsRepository(educator, employments, fromDate, toDate))
            {
                var appointments = repository.GetAppointments().ToList();
                var eventsDays   = daysOfWeek.Select(day =>
                {
                    var dayEvents = appointments
                                    .Where(a => a.IsPublicMaster && !a.IsCancelled)
                                    .Where(a => a.Start.DayOfWeek == day)
                                    .Select(a => new AggregatedContingent(a, language))
                                    .Select(ac => new AggregatedDates(ac, language))
                                    .GroupBy(ad => ad.Key)
                                    .OrderBy(ad => ad.Key.Start)
                                    .ThenBy(ad => ad.Key.Subject)
                                    .Select(g => new EducatorEventsContract.Event
                    {
                        Start                        = g.Key.Start,
                        End                          = g.Key.End,
                        Subject                      = g.Key.Subject,
                        Dates                        = new DateSeries(g.Select(ad => ad.Date), language).Select(d => d.ToString()),
                        TimeIntervalString           = g.Key.GetTimeIntervalString(),
                        EducatorsDisplayText         = g.Key.EducatorsDisplayText,
                        IsCanceled                   = g.Key.IsCanceled,
                        StudyEventsTimeTableKindCode = (int)g.Key.StudyEventsTimeTableKindCode,
                        ContingentUnitNames          = g.Key.ContingentUnits.Select(contingentNameMapper.Map),
                        EducatorIds                  = g.Key.EventLocations.SelectMany(el => el.Educators).Select(educatorIdMapper.Map),
                        EventLocations               = g.Key.EventLocations.Select(eventLocationMapper.Map)
                    })
                                    .ToList();

                    return(new EducatorEventsContract.EventsDay
                    {
                        Day = day,
                        DayString = DateTimeHelper.GetDayOfWeekStringByLanguage(day, language),
                        DayStudyEventsCount = dayEvents.Count(),
                        DayStudyEvents = dayEvents,
                    });
                })
                                   .ToList();

                return(new EducatorEventsContract
                {
                    From = fromDate,
                    To = toDate,
                    IsNextTerm = showNextTerm,
                    DisplayText = educatorDisplayText,
                    LongDisplayText = educatorLongDisplayText,
                    DateRangeDisplayText = string.Format("{0:d MMMM yyyy} - {1:d MMMM yyyy}", fromDate, toDate),
                    TimetableTitle = title,
                    Id = educator.Id,
                    IsSpringTerm = isSpringTerm,
                    SpringTermLinkAvailable = (isSpringTerm == showNext),
                    AutumnTermLinkAvailable = (isSpringTerm != showNext),
                    HasEvents = eventsDays.Any(d => d.DayStudyEvents.Any()),
                    EducatorEventsDays = eventsDays
                });
            }
        }