Exemplo n.º 1
0
        /// <summary>
        /// Object mapping from HTMLParser.DTO to Domain.Schedule object.
        /// </summary>
        /// <param name="timePlanEvents">HTMLParser.DTO entity</param>
        /// <param name="forDate">Schedule date</param>
        /// <returns>Domain.Schedule entity</returns>
        public static Schedule MapFromDto(List<TimePlanEvent> timePlanEvents, DateTime forDate)
        {
            var schedule = new Schedule
            {
                Date = forDate
            };

            var subjectsInSchedule = new List<SubjectInSchedule>();

            foreach (var tpEvent in timePlanEvents)
            {
                var newSubject = new Subject
                {
                    SubjectCode = tpEvent.SubjectCode,
                    SubjectName = tpEvent.SubjectName
                };

                var teacherInSubject = tpEvent.LecturersWithRoles.Select(lecturer =>
                    new TeacherInSubjectEvent
                    {
                        Teacher = new Teacher
                        {
                            FullName = string.Join(" ", lecturer.Trim().Split(" ").Where(e => e.ToCharArray().Any(char.IsUpper)).ToList()).Trim(),
                            Role = string.Join(" ", lecturer.Trim().Split(" ").Where(e => e.ToCharArray().All(char.IsLower)).ToList()).Trim()
                        }
                    }).ToList();

                var subjectInSchedule = new SubjectInSchedule()
                {
                    StartDateTime = tpEvent.StartDateTime,
                    EndDateTime = tpEvent.EndDateTime,
                    Groups = string.Join(", ", tpEvent.Groups),
                    Rooms = string.Join(", ", tpEvent.Locations),
                    Schedule = schedule,
                    Subject = newSubject,
                    TeacherInSubjectEvents = teacherInSubject,
                    UniqueIdentifier = tpEvent.EventIdentifier
                };

                subjectInSchedule.SubjectType = tpEvent.SubjectEventType.Trim() switch
                {
                    "praktikum" => (int) SubjectType.Practice,
                    "harjutus" => (int) SubjectType.Exercise,
                    "loeng" => (int) SubjectType.Lecture,
                    "loeng+harjutus" => (int) SubjectType.LectureAndExercise,
                    "loeng+praktikum" => (int) SubjectType.LectureAndPractice,
                    "praktikum+harjutus" =>(int) SubjectType.PracticeAndExercise,
                    "harjutus+praktikum" => (int) SubjectType.ExerciseAndPractice,
                    _ => (int) SubjectType.Unknown
                };

                subjectsInSchedule.Add(subjectInSchedule);
            }

            schedule.SubjectsInSchedules = subjectsInSchedule;

            return schedule;
        }
    }
Exemplo n.º 2
0
        public static DTO.SubjectInSchedule MapFromDomain(SubjectInSchedule subjectInSchedule)
        {
            var res = subjectInSchedule == null ? null : new DTO.SubjectInSchedule
            {
                Id               = subjectInSchedule.Id,
                CreatedAt        = subjectInSchedule.CreatedAt,
                ChangedAt        = subjectInSchedule.ChangedAt,
                CreatedBy        = subjectInSchedule.CreatedBy,
                ChangedBy        = subjectInSchedule.ChangedBy,
                SubjectId        = subjectInSchedule.SubjectId,
                Subject          = SubjectMapper.MapFromDomain(subjectInSchedule.Subject),
                ScheduleId       = subjectInSchedule.ScheduleId,
                Schedule         = ScheduleMapper.MapFromDomain(subjectInSchedule.Schedule),
                UniqueIdentifier = subjectInSchedule.UniqueIdentifier,
                SubjectType      = subjectInSchedule.SubjectType,
                Rooms            = subjectInSchedule.Rooms,
                Groups           = subjectInSchedule.Groups,
                StartDateTime    = subjectInSchedule.StartDateTime,
                EndDateTime      = subjectInSchedule.EndDateTime
            };

            return(res ?? default !);
        }
Exemplo n.º 3
0
        public static async Task GetAndSaveScheduleForScreen(IBLLApp bll, string userId, Screen screen)
        {
            var timeplanGettingSystem = new GetTimePlanFromInformationSystem(screen.Prefix);
            var schedule = timeplanGettingSystem.GetScheduleForToday();

            var bllSchedule =
                ScheduleMapper.MapFromInternal(DAL.App.Mappers.ScheduleMapper.MapFromDomain(schedule));

            bllSchedule.Prefix = screen.Prefix;

            var scheduleGuid = await bll.Schedules.AddAsync(bllSchedule);

            await bll.SaveChangesAsync();

            var scheduleIdAfterSaveChanges = bll.Schedules.GetUpdatesAfterUowSaveChanges(scheduleGuid).Id;

            var subjects = schedule.SubjectsInSchedules;

            if (subjects != null)
            {
                foreach (var subjectInSchedule in subjects)
                {
                    int subjectInScheduleId;
                    var subjectInScheduleThatAlreadyExists =
                        await bll.SubjectInSchedules.FindByUniqueIdentifierAsync(subjectInSchedule.UniqueIdentifier);

                    if (subjectInScheduleThatAlreadyExists != null)
                    {
                        subjectInScheduleThatAlreadyExists.ScheduleId = scheduleIdAfterSaveChanges;
                        bll.SubjectInSchedules.Update(subjectInScheduleThatAlreadyExists);
                        await bll.SaveChangesAsync();

                        subjectInScheduleId = subjectInScheduleThatAlreadyExists.Id;
                    }
                    else
                    {
                        var bllSubjectInSchedule = new SubjectInSchedule
                        {
                            CreatedAt        = DateTime.Now,
                            CreatedBy        = userId,
                            Rooms            = subjectInSchedule.Rooms,
                            Groups           = subjectInSchedule.Groups,
                            UniqueIdentifier = subjectInSchedule.UniqueIdentifier,
                            StartDateTime    = subjectInSchedule.StartDateTime,
                            EndDateTime      = subjectInSchedule.EndDateTime,
                            SubjectType      = subjectInSchedule.SubjectType,
                            ScheduleId       = scheduleIdAfterSaveChanges
                        };

                        var subject = await bll.Subjects
                                      .FindBySubjectNameAndCodeAsync(subjectInSchedule.Subject.SubjectName,
                                                                     subjectInSchedule.Subject.SubjectCode);

                        if (subject != null)
                        {
                            bllSubjectInSchedule.SubjectId = subject.Id;
                            bllSubjectInSchedule.Subject   = null;
                        }
                        else
                        {
                            var bllSubject = new Subject
                            {
                                CreatedAt   = DateTime.Now,
                                CreatedBy   = userId,
                                SubjectCode = subjectInSchedule.Subject.SubjectCode,
                                SubjectName = subjectInSchedule.Subject.SubjectName
                            };
                            var subjectGuid = await bll.Subjects.AddAsync(bllSubject);

                            await bll.SaveChangesAsync();

                            bllSubjectInSchedule.SubjectId = bll.Subjects.GetUpdatesAfterUowSaveChanges(subjectGuid).Id;
                        }
                        var subjInScheduleGuid = await bll.SubjectInSchedules.AddAsync(bllSubjectInSchedule);

                        await bll.SaveChangesAsync();

                        subjectInScheduleId =
                            bll.SubjectInSchedules.GetUpdatesAfterUowSaveChanges(subjInScheduleGuid).Id;
                    }

                    var teachers = new List <Teacher>();

                    if (subjectInSchedule.TeacherInSubjectEvents != null)
                    {
                        foreach (var teacherInSubjectEvent in subjectInSchedule.TeacherInSubjectEvents)
                        {
                            var teacher = await bll.Teachers
                                          .FindTeacherByNameAndRoleAsync(teacherInSubjectEvent.Teacher.FullName,
                                                                         teacherInSubjectEvent.Teacher.Role);

                            if (teacher != null)
                            {
                                teachers.Add(teacher);
                            }
                            else
                            {
                                var newTeacher = new Teacher
                                {
                                    CreatedAt   = DateTime.Now,
                                    CreatedBy   = userId,
                                    TeacherName = teacherInSubjectEvent.Teacher.FullName,
                                    TeacherRole = teacherInSubjectEvent.Teacher.Role
                                };
                                var teacherGuid = await bll.Teachers.AddAsync(newTeacher);

                                await bll.SaveChangesAsync();

                                teachers.Add(bll.Teachers.GetUpdatesAfterUowSaveChanges(teacherGuid));
                            }
                        }
                    }

                    foreach (var teacher in teachers)
                    {
                        bll.TeacherInSubjectEvents.Add(new TeacherInSubjectEvent
                        {
                            CreatedAt           = DateTime.Now,
                            CreatedBy           = userId,
                            TeacherId           = teacher.Id,
                            SubjectInScheduleId = subjectInScheduleId
                        });
                    }
                    await bll.SaveChangesAsync();
                }
            }

            await bll.ScheduleInScreens.AddAsync(new ScheduleInScreen
            {
                CreatedAt  = DateTime.Now,
                CreatedBy  = userId,
                ScreenId   = screen.Id,
                ScheduleId = scheduleIdAfterSaveChanges
            });

            var futureEvents = await bll.Events.GetAllFutureEventsAsync(DateTime.Now);

            foreach (var futureEvent in futureEvents)
            {
                if (futureEvent.ShowStartDateTime <= DateTime.Now && futureEvent.ShowEndDateTime > DateTime.Now)
                {
                    await bll.EventInSchedules.AddAsync(new EventInSchedule
                    {
                        CreatedAt  = DateTime.Now,
                        CreatedBy  = userId,
                        ScheduleId = scheduleIdAfterSaveChanges,
                        EventId    = futureEvent.Id
                    });
                }
            }

            await bll.SaveChangesAsync();
        }