protected override async Task HandleAbsenceEvent(AbsenceEvent @event, IIccOutput outputSettings)
        {
            Configure(outputSettings);
            tuitionResolver.Initialize();

            var absences = @event.Absences.Select(absence =>
            {
                var objective = absence.Objective;

                if (absence.Type == Absence.ObjectiveType.StudyGroup)
                {
                    objective = tuitionResolver.ResolveStudyGroup(absence.Objective);
                }

                return(new AbsenceData
                {
                    Date = absence.Date,
                    Objective = absence.Objective,
                    Type = ConvertObjectiveTypeToString(absence.Type),
                    LessonStart = absence.LessonStart,
                    LessonEnd = absence.LessonEnd
                });
            });

            var response = await iccImporter.ImportAbsencesAsync(absences.ToList());

            await HandleResponseAsync(response);
        }
Exemple #2
0
        public async Task <ImportResult> ImportAbsencesAsync(UntisExportResult result, DateTime?startDate, DateTime?endDate)
        {
            ConfigureImporter();

            var absences = result.Absences.Where(x => !x.IsInternal)
                           .SelectMany(absence =>
            {
                var absences    = new List <AbsenceData>();
                var currentDate = new DateTime(absence.Start.Ticks);

                while (currentDate <= absence.End)
                {
                    absences.Add(new AbsenceData
                    {
                        Date        = currentDate,
                        LessonStart = currentDate == absence.Start ? absence.LessonStart : result.Settings.NumberOfFirstLesson,
                        LessonEnd   = currentDate == absence.End ? absence.LessonEnd : result.Settings.NumberOfLessonsPerDay,
                        Objective   = absence.Objective,
                        Type        = GetAbsenceType(absence.Type)
                    });
                    currentDate = currentDate.AddDays(1);
                }

                return(absences.Where(x => startDate == null || endDate == null || (startDate <= x.Date && x.Date <= endDate)));
            }).ToList();

            var response = await importer.ImportAbsencesAsync(absences);

            return(HandleResponse(response));
        }