Engage.Survey.Entities.SurveyRepository.GetModuleIdForQuestion C# (CSharp) Method

GetModuleIdForQuestion() public method

Gets the ID of the module that the given question belongs to.
public GetModuleIdForQuestion ( int questionId ) : int
questionId int The question's ID.
return int
        public int GetModuleIdForQuestion(int questionId)
        {
            var moduleId = (from question in this.Context.Questions
                            where question.QuestionId == questionId
                            select question.Section.Survey.ModuleId).SingleOrDefault();

            return moduleId == default(int) ? Null.NullInteger : moduleId;
        }

Usage Example

        public void DeleteQuestion(int questionId)
        {
            var surveyRepository = new SurveyRepository();
            var moduleId = surveyRepository.GetModuleIdForQuestion(questionId);
            if (!this.CanEditModule(moduleId))
            {
                this.DenyAccess();
            }

            surveyRepository.DeleteQuestion(questionId);
        }