public void UpdateIndustryQuestions(IndustryQuestionModel model)
        {
            try
            {
                List<ChecklistTemplateQuestion> industryQuestions = _industryQuestionRepository.GetByQuestion(model.QuestionId);

                var user = _userForAuditingRepository.GetSystemUser();
                foreach (var iq in industryQuestions)
                {
                    iq.MarkForDelete(user);
                    _industryQuestionRepository.SaveOrUpdate(iq);
                }

                foreach (var industryId in model.IndustryIds)
                {
                    var indQuest = new ChecklistTemplateQuestion();
                    indQuest.Id = Guid.NewGuid();
                    indQuest.CreatedBy = user;
                    indQuest.CreatedOn = DateTime.Now;
                    indQuest.LastModifiedBy = user;
                    indQuest.LastModifiedOn = DateTime.Now;
                    indQuest.Deleted = false;

                    indQuest.ChecklistTemplate = _industryRepository.GetById(industryId);
                    indQuest.Question = _questionRepository.GetById(model.QuestionId);

                    _industryQuestionRepository.SaveOrUpdate(indQuest);
                }
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(typeof(IndustryController)).Error(ex);
                throw;
            }
        }
        public void Given_question_details_and_existing_industry_When_post_question_is_called_then_question_is_added_to_industry()
        {
            var industry1 = new ChecklistTemplate() { Id = Guid.NewGuid(), Name = "ChecklistTemplate 1" };
            var industry2 = new ChecklistTemplate() { Id = Guid.NewGuid(), Name = "ChecklistTemplate 2" };
            var industry3 = new ChecklistTemplate() { Id = Guid.NewGuid(), Name = "ChecklistTemplate 3" };

            _industryRepository
                  .Setup(x => x.GetById(industry1.Id))
                  .Returns(() => industry1);

            _industryRepository
                  .Setup(x => x.GetById(industry2.Id))
                  .Returns(() => industry2);

            _industryRepository
                  .Setup(x => x.GetById(industry3.Id))
                  .Returns(() => industry3);

            var returnedIndustries = new List<ChecklistTemplateQuestion>();

            Question q = new Question() { Title = "Q1" };

            ChecklistTemplateQuestion iq1 = new ChecklistTemplateQuestion() {Id = Guid.NewGuid(), Question = q, ChecklistTemplate = industry1};
            ChecklistTemplateQuestion iq2 = new ChecklistTemplateQuestion() {Id = Guid.NewGuid(), Question = q, ChecklistTemplate = industry3};
            returnedIndustries.Add( iq1 );
            returnedIndustries.Add( iq2 );

            _ChecklistTemplateQuestionRepository
                .Setup(x => x.GetByQuestion(It.IsAny<Guid>()))
                .Returns(returnedIndustries);

            ChecklistTemplateQuestion indQuest1 = null;
            ChecklistTemplateQuestion indQuest2 = null;
            _ChecklistTemplateQuestionRepository
                .Setup(x => x.SaveOrUpdate( iq1))
                .Callback(
                    delegate(ChecklistTemplateQuestion x)
                    {
                        indQuest1 = x;
                    }
                );

            _ChecklistTemplateQuestionRepository
                .Setup(x => x.SaveOrUpdate(iq2))
                .Callback(
                    delegate(ChecklistTemplateQuestion x)
                    {
                        indQuest2 = x;
                    }
                );

            _questionRepository
               .Setup(x => x.GetById(It.IsAny<Guid>()))
               .Returns(q);

            var industryModel = new IndustryQuestionModel();
            industryModel.QuestionId = q.Id;
            industryModel.IndustryIds = new List<Guid>();
            industryModel.IndustryIds.Add( industry2.Id);

            var controller = GetTarget();
            controller.UpdateIndustryQuestions(industryModel);

            Assert.IsTrue(indQuest1.Deleted);
            Assert.IsTrue(indQuest2.Deleted);

            _ChecklistTemplateQuestionRepository.Verify(x => x.SaveOrUpdate(iq1), Times.Once);
            _ChecklistTemplateQuestionRepository.Verify(x => x.SaveOrUpdate(iq2), Times.Once);
        }