示例#1
0
        public void UpdateTimetable(ApplicationContext context, TimetableEntity timetableEntity,
                                    TimetableEntity newTimetable)
        {
            timetableEntity.Updated    = DateTime.UtcNow;
            timetableEntity.IsApproved = false;
            timetableEntity.Hash       = newTimetable.Hash;

            UpdateGroups(timetableEntity.Groups, newTimetable.Groups);
            UpdateSubjects(timetableEntity.Subjects, newTimetable.Subjects);

            context.SaveChanges();
        }
示例#2
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);
        }
示例#3
0
        public ServiceResult UpdateApprovedStatus(int timetableId)
        {
            TimetableEntity timetable = Context.Timetables
                                        .Include(t => t.Subjects)
                                        .FirstOrDefault(t => t.Id == timetableId);

            if (timetable == null)
            {
                return(new ServiceResult(Result.NotFound));
            }

            timetable.IsApproved = timetable.Subjects.All(s => s.IsApproved);
            Context.SaveChanges();

            return(new ServiceResult(Result.OK, timetable.Id));
        }
示例#4
0
        public void StartCheckTimetables(object sender, EventArgs e)
        {
            var parserArgs       = e as ParserEventArgs;
            var timetableChecker = new TimetableUpdater();

            List <TimetableModel> timetables = parserArgs.Timetables;

            DbContextOptions options = new DbContextOptionsBuilder()
                                       .UseNpgsql(_connectionString, o => o.SetPostgresVersion(9, 6)).Options;

            using (var context = new ApplicationContext(options))
            {
                foreach (TimetableModel timetable in timetables)
                {
                    TimetableEntity timetableEntity = context.Timetables
                                                      .Include(t => t.Groups)
                                                      .Include(t => t.Subjects)
                                                      .ThenInclude(s => s.Info)
                                                      .Include(t => t.Subjects)
                                                      .ThenInclude(s => s.Days)
                                                      .ThenInclude(d => d.Periods)
                                                      .SingleOrDefault(t => t.Key == timetable.Key);

                    TimetableEntity newTimetable = (new EntityMapper()).MapTimetable(timetable);

                    if (timetableEntity == null)
                    {
                        timetableChecker.AddTimetable(context, newTimetable);

                        // if (added) need notify?
                        continue;
                    }

                    if (timetableChecker.IsSameTimetable(timetableEntity, newTimetable))
                    {
                        timetableEntity.NotChanged = DateTime.UtcNow;
                        context.SaveChanges();
                        continue;
                    }

                    timetableChecker.UpdateTimetable(context, timetableEntity, newTimetable);
                    // if (updated) need notify?
                }
            }
        }
示例#5
0
 public void AddTimetable(ApplicationContext context, TimetableEntity newTimetable)
 {
     newTimetable.Created = DateTime.UtcNow;
     context.Timetables.Add(newTimetable);
     context.SaveChanges();
 }
示例#6
0
 public bool IsSameTimetable(TimetableEntity timetable, TimetableEntity newTimetable)
 {
     return(HashCoder.IsSameHashes(timetable.Hash, newTimetable.Hash));
 }