Ejemplo n.º 1
0
        private SubjectEntity MapOneSubject(SubjectModel subjectModel)
        {
            string subjectJson = TimetableSerializer.SerializeToJson(subjectModel);
            string subjectHash = HashCoder.GetSha256Hash(subjectJson);

            var info = new SubjectInfoEntity
            {
                Title             = subjectModel.Title,
                Teachers          = subjectModel.Teachers,
                LectureStartDate  = subjectModel.LectureStartDate,
                LectureEndDate    = subjectModel.LectureEndDate,
                PracticeStartDate = subjectModel.PracticeStartDate,
                PracticeEndDate   = subjectModel.PracticeEndDate
            };

            string infoJson = TimetableSerializer.SerializeToJson(info);
            string infoHash = HashCoder.GetSha256Hash(infoJson);

            info.Hash = infoHash;

            string daysJson = TimetableSerializer.SerializeToJson(subjectModel.Days);
            string daysHash = HashCoder.GetSha256Hash(daysJson);

            SubjectEntity entity = new SubjectEntity
            {
                Info     = info,
                Days     = MapSchoolDays(subjectModel.Days),
                HashDays = daysHash,
                Hash     = subjectHash
            };

            return(entity);
        }
Ejemplo n.º 2
0
        private SchoolDayEntity MapOneSchoolDay(SchoolDayModel day)
        {
            string dayJson = TimetableSerializer.SerializeToJson(day);
            string dayHash = HashCoder.GetSha256Hash(dayJson);

            var entity = new SchoolDayEntity
            {
                Day             = day.Day,
                IsDayOfEvenWeek = day.IsDayOfEvenWeek,
                Periods         = MapPeriods(day.Periods),
                Hash            = dayHash
            };

            return(entity);
        }
Ejemplo n.º 3
0
        public TimetableEntity MapTimetable(TimetableModel timetableModel)
        {
            string jsonTimetable = TimetableSerializer.SerializeToJson(timetableModel);
            string hashTimetable = HashCoder.GetSha256Hash(jsonTimetable);

            var entity = new TimetableEntity
            {
                Key      = timetableModel.Key,
                Groups   = MapGroups(timetableModel.Groups),
                Subjects = MapSubjects(timetableModel.Subjects),
                Hash     = hashTimetable
            };

            return(entity);
        }
Ejemplo n.º 4
0
        private void UpdateSubject(SubjectEntity subject, SubjectEntity newSubject)
        {
            subject.Hash       = newSubject.Hash;
            subject.IsApproved = false;

            if (!HashCoder.IsSameHashes(subject.Info.Hash, newSubject.Info.Hash))
            {
                UpdateSubjectInfo(subject.Info, newSubject.Info);
            }

            if (HashCoder.IsSameHashes(subject.HashDays, newSubject.HashDays))
            {
                return;
            }

            UpdateDays(subject.Days, newSubject.Days);
        }
Ejemplo n.º 5
0
        private PeriodEntity MapOnePeriod(PeriodModel period)
        {
            string periodJson = TimetableSerializer.SerializeToJson(period);
            string periodHash = HashCoder.GetSha256Hash(periodJson);

            var entity = new PeriodEntity
            {
                Number        = period.Number,
                Cabinet       = period.Cabinet,
                Subgroup      = period.Subgroup,
                IsLecture     = period.IsLecture,
                Option        = period.Modification.Option,
                OptionDate    = period.Modification.Date,
                OptionCabinet = period.Modification.Cabinet,
                Hash          = periodHash
            };

            return(entity);
        }
Ejemplo n.º 6
0
        private void UpdateSubjects(List <SubjectEntity> subjects, IReadOnlyCollection <SubjectEntity> newSubjects)
        {
            subjects.RemoveAll(s => newSubjects.All(n => n.Info.Title != s.Info.Title));

            foreach (SubjectEntity newSubject in newSubjects)
            {
                SubjectEntity subjectEntity = subjects.FirstOrDefault(s => s.Info.Title == newSubject.Info.Title);

                if (subjectEntity == null)
                {
                    subjects.Add(newSubject);
                    continue;
                }

                if (HashCoder.IsSameHashes(subjectEntity.Hash, newSubject.Hash))
                {
                    continue;
                }

                UpdateSubject(subjectEntity, newSubject);
            }
        }
Ejemplo n.º 7
0
        private void UpdatePeriods(List <PeriodEntity> periods, IReadOnlyCollection <PeriodEntity> newPeriods)
        {
            periods.RemoveAll(p => newPeriods.All(n => n.Number != p.Number));

            foreach (PeriodEntity newPeriod in newPeriods)
            {
                PeriodEntity periodEntity = periods.FirstOrDefault(p => p.Number == newPeriod.Number);

                if (periodEntity == null)
                {
                    periods.Add(newPeriod);
                    continue;
                }

                if (HashCoder.IsSameHashes(periodEntity.Hash, newPeriod.Hash))
                {
                    continue;
                }

                UpdatePeriod(periodEntity, newPeriod);
            }
        }
Ejemplo n.º 8
0
        private void UpdateDays(List <SchoolDayEntity> days, IReadOnlyCollection <SchoolDayEntity> newDays)
        {
            days.RemoveAll(d => newDays.All(n => n.Day != d.Day && n.IsDayOfEvenWeek != d.IsDayOfEvenWeek));

            foreach (SchoolDayEntity newDay in newDays)
            {
                SchoolDayEntity dayEntity = days
                                            .FirstOrDefault(d => d.Day == newDay.Day && d.IsDayOfEvenWeek == newDay.IsDayOfEvenWeek);

                if (dayEntity == null)
                {
                    days.Add(newDay);
                    continue;
                }

                if (HashCoder.IsSameHashes(dayEntity.Hash, newDay.Hash))
                {
                    continue;
                }

                UpdateDay(dayEntity, newDay);
            }
        }
Ejemplo n.º 9
0
 public bool IsSameTimetable(TimetableEntity timetable, TimetableEntity newTimetable)
 {
     return(HashCoder.IsSameHashes(timetable.Hash, newTimetable.Hash));
 }