public void UpdatePreQualifiedTestAnswers(long customerId, long eventId, long oldEventId, long orgUserId) { var isMammoEvent = _eventTestRepository.EventHasMammoTests(eventId); if (!isMammoEvent) { return; } long version = _eventCustomerQuestionAnswerRepository.GetLatestVersion(customerId, eventId); var disqualifiedVersion = _disqualifiedTestRepository.GetLatestVersion(customerId, oldEventId); var eventQuestionAnswer = _eventCustomerQuestionAnswerRepository.GetAllByCustomerIdEventId(customerId, oldEventId); var eventQuestionAnswerModel = _eventCustomerQuestionAnswerFactory.CreateEventCustomerQuestionAnswerListModel(eventQuestionAnswer, customerId, eventId, orgUserId, version); var disqualifiedQuestion = _disqualifiedTestRepository.GetAllByEventCustomerId(customerId, oldEventId, Convert.ToInt32(disqualifiedVersion)); var disqualifiedQuestionModel = _eventCustomerQuestionAnswerFactory.CreateDisqualifiedTestListModel(disqualifiedQuestion, customerId, eventId, orgUserId, Convert.ToInt32(version)); var dependentDisqualifiedTest = _dependentDisqualifiedTestRepository.GetAllByEventCustomerId(customerId, oldEventId, Convert.ToInt32(disqualifiedVersion)); var eventIds = new long[] { oldEventId, eventId }; using (var scope = new TransactionScope()) { _eventCustomerQuestionAnswerRepository.DeleteEventCustomerQuestionAnswers(customerId, eventIds, orgUserId); _eventCustomerQuestionAnswerRepository.SaveAnswer(eventQuestionAnswerModel); _disqualifiedTestRepository.DeleteDisqualifiedTests(customerId, eventIds, orgUserId); _dependentDisqualifiedTestRepository.DeleteDependentDisqualifiedTests(customerId, eventIds, orgUserId); if (!disqualifiedQuestionModel.IsNullOrEmpty()) { var disqualifiedEventTests = _eventTestRepository.GetByEventAndTestIds(eventId, disqualifiedQuestion.Select(x => x.TestId).ToArray()); var disqualifiedTestTemplateIds = disqualifiedEventTests.Where(x => x.PreQualificationQuestionTemplateId.HasValue).Select(x => x.PreQualificationQuestionTemplateId.Value); var dependentDisqualifiedTestIds = _preQualificationTemplateDependentTestRepository.GetByTemplateIds(disqualifiedTestTemplateIds.ToArray()) .Where(x => disqualifiedTestTemplateIds.Contains(x.TemplateId)).Select(x => x.TestId); //var disqualifiedModel = _eventCustomerQuestionAnswerFactory.GetDisqualifiedTestListModel(disqualified, customerId, eventId, disqualifiedVersion, orgUserId); _disqualifiedTestRepository.SaveAnswer(disqualifiedQuestionModel); var dependentDisqualifiedTests = _eventCustomerQuestionAnswerFactory.GetDependentDisqualifiedTestDomains(customerId, eventId, dependentDisqualifiedTestIds, Convert.ToInt32(version), orgUserId, null); _dependentDisqualifiedTestRepository.Save(dependentDisqualifiedTests); } scope.Complete(); } }