Exemplo n.º 1
0
        public async Task <bool> IsHaveAdditionalVariable(Guid?optionGroupId)
        {
            var optionChoices = await optionChoiceService.GetListByOptionGroupId(optionGroupId, true);

            var item = optionChoices.Where(x => x.IsAdditionalChoise == true).SingleOrDefault();

            return(item == null ? false : true);
        }
Exemplo n.º 2
0
        private void UpdateRadioQuestion(RadioQuestionModel data)
        {
            var question = GetQuestionById(Guid.Parse(data.Id));

            question.Name             = data.Text;
            question.Description      = data.Description;
            question.Required         = data.Required;
            question.OrderNo          = data.Order;
            question.AdditionalAnswer = data.IsAdditionalAnswer;
            UpdateQuestion(question);
            var optionChoiseList = _optionChoiceService.GetListByOptionGroupId(question.OptionGroupId).Result;

            foreach (var item in optionChoiseList)
            {
                var result = data.Options.Find(x => x.Id == item.Id.ToString());
                if (result != null)
                {
                    item.Name = result.Value;
                    _optionChoiceService.UpdateOptionChoise(item);
                    data.Options.Remove(result); // Delete an item from updated option list to getting the only new options
                }
                else
                {
                    DeleteOptionChoises(item.Id);

                    _optionChoiceService.DeleteOptionChoise(item);
                }
            }

            if (data.IsAdditionalAnswer)
            {
                ItemModel item = new ItemModel()
                {
                    IsAdditionalChoise = true,
                    Value = "Additional answer radio"
                };
                var excistAdditional = _optionChoiceService.GetListByOptionGroup(question.OptionGroupId, true).Result.Where(x => x.IsAdditionalChoise == true).FirstOrDefault();
                if (excistAdditional == null)
                {
                    data.Options.Add(item);
                }
            }
            _optionChoiceService.AddRange(question.OptionGroupId.Value, data.Options);
        }
        private void SaveTextAnswer(TextAnswerModel data)
        {
            if (data.Answer.Length > 0)
            {
                var optionChoice     = _optionChoiceService.GetListByOptionGroupId(data.OptionGroupId).Result.FirstOrDefault();
                var questionOptionId = _questionOptionService.Add(data.Id, optionChoice.Id);

                Answers answer = new Answers()
                {
                    AnswerBoolean    = false,
                    AnswerDateTime   = null,
                    AnswerNumeric    = null,
                    AnswerText       = data.Answer,
                    RespondentId     = respondentId,
                    QuestionOptionId = questionOptionId
                };
                var answerId = AddAsync(answer).Result;
            }
        }