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(); }
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); }
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)); }
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? } } }
public void AddTimetable(ApplicationContext context, TimetableEntity newTimetable) { newTimetable.Created = DateTime.UtcNow; context.Timetables.Add(newTimetable); context.SaveChanges(); }
public bool IsSameTimetable(TimetableEntity timetable, TimetableEntity newTimetable) { return(HashCoder.IsSameHashes(timetable.Hash, newTimetable.Hash)); }