/// <summary> /// Syncs employments for all People in OS2 database to DMZ database. /// </summary> private void SyncEmployments() { var i = 0; var personList = _masterPersonRepo.AsQueryable().ToList(); var max = personList.Count; foreach (var person in personList) { i++; if (i % 10 == 0) { Console.WriteLine("Syncing employments for person " + i + " of " + max); } var pers = _dmzProfileRepo.AsQueryable().First(x => x.Id == person.Id); var employments = pers.Employments; // Migrate list of employees as the model is not the same in DMZ and OS2. foreach (var masterEmployment in person.Employments) { var dmzEmployment = employments.FirstOrDefault(x => x.Id == masterEmployment.Id); var employment = new Employment { Id = masterEmployment.Id, ProfileId = masterEmployment.PersonId, StartDateTimestamp = masterEmployment.StartDateTimestamp, EndDateTimestamp = masterEmployment.EndDateTimestamp, EmploymentPosition = masterEmployment.Position + " - " + masterEmployment.OrgUnit.LongDescription, }; employment = Encryptor.EncryptEmployment(employment); if (dmzEmployment == null) { employments.Add(employment); } else { dmzEmployment.ProfileId = employment.ProfileId; dmzEmployment.StartDateTimestamp = masterEmployment.StartDateTimestamp; dmzEmployment.EndDateTimestamp = masterEmployment.EndDateTimestamp; dmzEmployment.EmploymentPosition = employment.EmploymentPosition; } } } _dmzProfileRepo.Save(); }
/// <summary> /// Syncs employments for all People in OS2 database to DMZ database. /// </summary> private void SyncEmployments() { var i = 0; var personList = _masterPersonRepo.AsQueryable().ToList(); var max = personList.Count; _logger.Debug($"{this.GetType().Name}, SyncEmployments(), Amount of persons= {max}"); foreach (var person in personList) { i++; if (i % 10 == 0) { Console.WriteLine("Syncing employments for person " + i + " of " + max); } try { var pers = _dmzProfileRepo.AsQueryable().First(x => x.Id == person.Id); var employments = pers.Employments; // Migrate list of employees as the model is not the same in DMZ and OS2. foreach (var masterEmployment in person.Employments) { var dmzEmployment = employments.FirstOrDefault(x => x.Id == masterEmployment.Id); var employment = new Employment { Id = masterEmployment.Id, ProfileId = masterEmployment.PersonId, ManNr = masterEmployment.EmploymentId.ToString(), StartDateTimestamp = masterEmployment.StartDateTimestamp, EndDateTimestamp = masterEmployment.EndDateTimestamp, EmploymentPosition = masterEmployment.Position + " - " + masterEmployment.OrgUnit.LongDescription, OrgUnitId = masterEmployment.OrgUnitId }; employment = Encryptor.EncryptEmployment(employment); if (dmzEmployment == null) { employments.Add(employment); } else { dmzEmployment.ProfileId = employment.ProfileId; dmzEmployment.ManNr = employment.ManNr; dmzEmployment.StartDateTimestamp = masterEmployment.StartDateTimestamp; dmzEmployment.EndDateTimestamp = masterEmployment.EndDateTimestamp; dmzEmployment.EmploymentPosition = employment.EmploymentPosition; dmzEmployment.OrgUnitId = employment.OrgUnitId; } } } catch (Exception ex) { _logger.Error($"{this.GetType().Name}, SyncToDmz(), Exception during sync to DMZ for employments from OS2 database to DMZ database, personId= {person.Id}. Exception: {ex.Message}", ex); } } _dmzProfileRepo.Save(); }