private async Task <int> WriteCategoriesQuestionAnswer(SchemeQuestionWithChildQuestionsDto schemeQuestion) { var error = ExportResult.NoError; foreach (var category in _schemeCategories) { _schemeCategory = category; dynamic codedQuestion; if (_validated) { codedQuestion = await _unitOfWork.ValidatedCategoryQuestions.SingleOrDefaultAsync(vcq => vcq.ProjectJurisdiction.Id == _projectJurisdiction.Id && vcq.SchemeQuestion.Id == schemeQuestion.Id && vcq.Category.Id == _schemeCategory.Id); } else { codedQuestion = await _unitOfWork.CodedCategoryQuestions.SingleOrDefaultAsync(vcq => vcq.ProjectJurisdiction.Id == _projectJurisdiction.Id && vcq.SchemeQuestion.Id == schemeQuestion.Id && vcq.Category.Id == _schemeCategory.Id && vcq.CodedBy.Id == _userId); } error = WriteQuestionAnswer(schemeQuestion, codedQuestion); if (error != ExportResult.NoError) { return(error); } } return(error); }
/// <summary> /// Write the header for each category for a given question /// </summary> /// <param name="schemeQuestion"></param> private int WriteSchemeCategoryQuestionHeader(SchemeQuestionWithChildQuestionsDto schemeQuestion) { foreach (var category in _schemeCategories) { _schemeCategory = category; var error = WriteSchemeQuestionHeader(schemeQuestion); if (error < ExportResult.NoError) { return(error); } } return(ExportResult.NoError); }
private int WriteCategoryQuestionCodebookEntries(SchemeQuestionWithChildQuestionsDto categoryQuestion) { foreach (var category in _schemeCategories) { _schemeCategory = category; var error = WriteQuestionCodebookEntries(categoryQuestion); if (error < ExportResult.NoError) { return(error); } } return(ExportResult.NoError); }
/// <summary> /// Goes thru all questions and child questions recursively and calls the appropriate method to write the header /// </summary> /// <param name="schemeQuestions"></param> private int WriteSchemeQuestionHeaders(List <SchemeQuestionWithChildQuestionsDto> schemeQuestions) { var currentQuestionOutlinePosition = 1; var outlinePrefixNumber = _outlineNumber; var error = ExportResult.NoError; foreach (var schemeQuestion in schemeQuestions) { _outlineNumber = outlinePrefixNumber + currentQuestionOutlinePosition.ToString(); // set categories if a category question if (schemeQuestion.QuestionType == QuestionType.Category) { _schemeCategories = schemeQuestion.PossibleAnswers; error = WriteSchemeQuestionHeader(schemeQuestion); } else if (schemeQuestion.IsCategoryQuestion) { error = WriteSchemeCategoryQuestionHeader(schemeQuestion); } else // no longer doing catgeory questions { _schemeCategories = null; _schemeCategory = null; error = WriteSchemeQuestionHeader(schemeQuestion); } if (schemeQuestion.ChildQuestions.Count > 0 && error == ExportResult.NoError) { _outlineNumber = _outlineNumber + "c"; error = WriteSchemeQuestionHeaders(schemeQuestion.ChildQuestions); } if (error != ExportResult.NoError) { return(error); } currentQuestionOutlinePosition += 1; } return(error); }
public ProjectExportService(IUnitOfWork unitOfWork, IWebHostEnvironment environment, ILogger <ProjectExportService> logger) { _unitOfWork = unitOfWork; _environment = environment; _logger = logger; _csvWriter = null; _projectId = 0; _project = null; _projectJurisdiction = null; _schemeTree = null; _codedTextExport = false; _schemeCategories = null; _codedCategories = null; _schemeCategory = null; _outlineNumber = ""; _processingCategoryQuestions = false; _userId = -1; _codedUser = null; _validated = true; }
private async Task <int> WriteQuestionAnswers(List <SchemeQuestionWithChildQuestionsDto> schemeQuestions) { var error = ExportResult.NoError; foreach (var schemeQuestion in schemeQuestions) { // set categories if a category question if (schemeQuestion.QuestionType == QuestionType.Category) { _processingCategoryQuestions = true; _schemeCategories = schemeQuestion.PossibleAnswers; dynamic codedQuestion; if (_validated) { codedQuestion = await _unitOfWork.ValidatedQuestions.SingleOrDefaultAsync(vq => vq.ProjectJurisdiction.Id == _projectJurisdiction.Id && vq.SchemeQuestion.Id == schemeQuestion.Id); } else { codedQuestion = await _unitOfWork.CodedQuestions.SingleOrDefaultAsync(vq => vq.ProjectJurisdiction.Id == _projectJurisdiction.Id && vq.SchemeQuestion.Id == schemeQuestion.Id && vq.CodedBy.Id == _userId); } _codedCategories = codedQuestion != null ? codedQuestion.CodedAnswers : null; error = WriteQuestionAnswer(schemeQuestion, codedQuestion); } else if (schemeQuestion.IsCategoryQuestion) { error = await WriteCategoriesQuestionAnswer(schemeQuestion); } else // no longer doing catgeory questions { _processingCategoryQuestions = false; _schemeCategories = null; _schemeCategory = null; dynamic codedQuestion; if (_validated) { codedQuestion = await _unitOfWork.ValidatedQuestions.SingleOrDefaultAsync(vq => vq.ProjectJurisdiction.Id == _projectJurisdiction.Id && vq.SchemeQuestion.Id == schemeQuestion.Id); } else { codedQuestion = await _unitOfWork.CodedQuestions.SingleOrDefaultAsync(vq => vq.ProjectJurisdiction.Id == _projectJurisdiction.Id && vq.SchemeQuestion.Id == schemeQuestion.Id && vq.CodedBy.Id == _userId); } error = WriteQuestionAnswer(schemeQuestion, codedQuestion); } if (schemeQuestion.ChildQuestions.Count > 0) { error = await WriteQuestionAnswers(schemeQuestion.ChildQuestions); } if (error != ExportResult.NoError) { return(error); } } return(error); }