示例#1
0
        private BaseQuestionModel GetCheckboxQuestion(QuestionsDto questionDto, string type)
        {
            var options = _optionChoiceService.GetListByOptionGroup(questionDto.OptionGroupId).Result;
            CheckBoxQuesstionModel checkboxQuestion = new CheckBoxQuesstionModel()
            {
                Id                 = questionDto.Id.ToString(),
                Text               = questionDto.Name,
                Order              = questionDto.OrderNo,
                ControlType        = type,
                Description        = questionDto.Description,
                IsAdditionalAnswer = questionDto.AdditionalAnswer,
                Required           = questionDto.Required,
                Options            = options
            };

            return(checkboxQuestion as BaseQuestionModel);
        }
示例#2
0
        private void UpdateCheckboxQuestion(CheckBoxQuesstionModel 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 checkbox"
                };
                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);
        }