예제 #1
0
        public async Task AddChoiceOptionAnswerToRowAnswerAsync(int surveyId, int rowAnswerId, int optionPosition,
                                                                bool value,
                                                                string viewValue)
        {
            var rowAnswer = await _rowAnswerRepository.GetByIdAsync(rowAnswerId);

            var fieldDataAnswer = await _fieldDataAnswerRepository.GetByIdAsync(rowAnswer.FieldDataAnswerId);

            var rowChoiceOptionAnswer = new RowChoiceOptionAnswer(optionPosition, value, viewValue);

            rowAnswer.AddChoiceOptionAnswer(rowChoiceOptionAnswer);
            await _rowChoiceOptionAnswerRepository.AddAsync(rowChoiceOptionAnswer);

            var questionAnswer = await _questionAnswerRepository.GetByIdAsync(fieldDataAnswer.QuestionAnswerId);

            var surveyReport = await _surveyReportRepository.GetBySurveyIdAsync(surveyId);

            var questionReport =
                await _questionReportRepository.GetBySurveyReportContentAndPositionAsync(surveyReport.Id,
                                                                                         questionAnswer.QuestionPosition,
                                                                                         questionAnswer.Select);

            if (!questionAnswer.IsRequired)
            {
                var counter = 0;
                foreach (var RowChoiceOptionAnswer in rowAnswer.RowChoiceOptionAnswers)
                {
                    if (RowChoiceOptionAnswer.Value)
                    {
                        counter++;
                    }
                }
                if (counter == 0)
                {
                    questionReport.DeleteAnswer();
                    await Task.CompletedTask;
                }
            }
            if (rowChoiceOptionAnswer.Value == true)
            {
                foreach (var dataSet in questionReport.DataSets)
                {
                    if (dataSet.Label != rowChoiceOptionAnswer.ViewValue)
                    {
                        continue;
                    }
                    var index        = dataSet._data[rowChoiceOptionAnswer.RowAnswer.RowPosition];
                    var labelCounter = int.Parse(index);
                    labelCounter++;
                    dataSet._data[rowAnswer.RowPosition] = labelCounter.ToString();
                    await _dataSetRepository.UpdateAsync(dataSet);
                }
            }
        }
        public async Task AddAsync(RowChoiceOptionAnswer rowChoiceOptionAnswer)
        {
            await _context.RowChoiceOptionsAnswers.AddAsync(rowChoiceOptionAnswer);

            await _context.SaveChangesAsync();
        }