Exemple #1
0
        private BaseQuestionModel GetGridRadioQuestion(QuestionsDto questionDto, string type)
        {
            var rowQuestions     = GetListByBaseQuestion(questionDto.Id).Result;
            var colOptionChoises = _optionChoiceService.GetListByOptionGroup(questionDto.OptionGroupId).Result;
            GridRadioQuestionModel gridQuestion = new GridRadioQuestionModel()
            {
                Id                 = questionDto.Id.ToString(),
                Text               = questionDto.Name,
                Order              = questionDto.OrderNo,
                ControlType        = type,
                Description        = questionDto.Description,
                IsAdditionalAnswer = questionDto.AdditionalAnswer,
                Required           = questionDto.Required,
                Grid               = new GridOptionsModel()
                {
                    Rows = new List <ItemModel>(),
                    Cols = colOptionChoises
                }
            };

            foreach (var row in rowQuestions)
            {
                ItemModel item = new ItemModel()
                {
                    Id    = row.Id.ToString(),
                    Label = "",
                    Value = row.Name,
                    Order = 0 // stub
                };
                gridQuestion.Grid.Rows.Add(item);
            }
            return(gridQuestion as BaseQuestionModel);
        }
Exemple #2
0
        public BaseQuestionModel GetQuestionByType(string baseQuestion)
        {
            BaseQuestionModel baseQuestionM = JsonConvert.DeserializeObject <BaseQuestionModel>(baseQuestion);

            if (Enum.TryParse(baseQuestionM.ControlType.ToString(), out type))
            {
                switch (type)
                {
                case QuestionTypes.Textbox:
                {
                    TextQuestionModel question = JsonConvert.DeserializeObject <TextQuestionModel>(baseQuestion);
                    baseQuestionM = question as BaseQuestionModel;
                    break;
                }

                case QuestionTypes.Textarea:
                {
                    TextAreaQuestionModel question = JsonConvert.DeserializeObject <TextAreaQuestionModel>(baseQuestion);
                    baseQuestionM = question as BaseQuestionModel;
                    break;
                }

                case QuestionTypes.Radio:
                {
                    RadioQuestionModel question = JsonConvert.DeserializeObject <RadioQuestionModel>(baseQuestion);
                    baseQuestionM = question as BaseQuestionModel;
                    break;
                }

                case QuestionTypes.Checkbox:
                {
                    CheckBoxQuesstionModel question = JsonConvert.DeserializeObject <CheckBoxQuesstionModel>(baseQuestion);
                    baseQuestionM = question as BaseQuestionModel;
                    break;
                }

                case QuestionTypes.Dropdown:
                {
                    DropdownQuestionModel question = JsonConvert.DeserializeObject <DropdownQuestionModel>(baseQuestion);
                    baseQuestionM = question as BaseQuestionModel;
                    break;
                }

                case QuestionTypes.GridRadio:
                {
                    GridRadioQuestionModel question = JsonConvert.DeserializeObject <GridRadioQuestionModel>(baseQuestion);
                    baseQuestionM = question as BaseQuestionModel;

                    break;
                }
                }
            }
            return(baseQuestionM);
        }
Exemple #3
0
        private void SaveGridRadioQuestion(GridRadioQuestionModel data)
        {
            InputTypesDto type             = inputTypeList.Where(item => item.Name == data.ControlType).FirstOrDefault();
            Guid          optionGroupId    = _optionGroupService.AddAsync(optionGroupDefinitions.gridRadio).Result;
            var           parentQuestionId = SaveQuestion(data, false, optionGroupId, type.Id, null).Result;

            if (data.Grid.Rows.Count() > 0)
            {
                var           rowTypeName = QuestionTypes.Radio.ToString();
                InputTypesDto rowsType    = inputTypeList.Where(item => item.Name == rowTypeName).FirstOrDefault();
                foreach (var item in data.Grid.Rows)
                {
                    BaseQuestionModel rowQuestion = new BaseQuestionModel()
                    {
                        Text               = item.Value,
                        Description        = "",
                        ControlType        = rowTypeName,
                        IsAdditionalAnswer = false,
                        Required           = data.Required,
                        Order              = 0, // stub
                    };
                    var rowQuestionId = SaveQuestion(rowQuestion, false, optionGroupId, rowsType.Id, parentQuestionId).Result;
                }
            }
            if (data.Grid.Cols.Count() > 0)
            {
                _optionChoiceService.AddRange(optionGroupId, data.Grid.Cols);
            }
            if (data.IsAdditionalAnswer)
            {
                ItemModel item = new ItemModel()
                {
                    IsAdditionalChoise = true,
                    Value = "Additional answer gridRadio"
                };
                _optionChoiceService.AddAsync(optionGroupId, item, true);
            }
        }
Exemple #4
0
        private void UpdateGridRadioQuestion(GridRadioQuestionModel 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.Grid.Cols.Find(x => x.Id == item.Id.ToString());
                if (result != null)
                {
                    item.Name = result.Value;
                    _optionChoiceService.UpdateOptionChoise(item);
                    data.Grid.Cols.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 gridRadio"
                };
                var excistAdditional = _optionChoiceService.GetListByOptionGroup(question.OptionGroupId, true).Result.Where(x => x.IsAdditionalChoise == true).FirstOrDefault();
                if (excistAdditional == null)
                {
                    _optionChoiceService.AddAsync(question.OptionGroupId.Value, item, true);
                }
            }
            _optionChoiceService.AddRange(question.OptionGroupId.Value, data.Grid.Cols);
            var rowQuestionList = GetListByParentId(question.Id);

            foreach (var item in rowQuestionList)
            {
                var result = data.Grid.Rows.Find(x => x.Id == item.Id.ToString());
                if (result != null)
                {
                    item.Name    = result.Value;
                    item.OrderNo = 0; // stub
                    UpdateQuestion(item);
                    data.Grid.Rows.Remove(result);
                }
                else
                {
                    DeleteQuestionById(item.Id);
                }
            }
            if (data.Grid.Rows.Count() > 0)
            {
                foreach (var row in data.Grid.Rows)
                {
                    var               rowTypeName = QuestionTypes.Radio.ToString();
                    InputTypesDto     rowsType    = inputTypeList.Where(item => item.Name == rowTypeName).FirstOrDefault();
                    BaseQuestionModel rowQuestion = new BaseQuestionModel()
                    {
                        Text               = row.Value,
                        Description        = "",
                        ControlType        = rowTypeName,
                        IsAdditionalAnswer = false,
                        Required           = data.Required,
                        Order              = 0, // stub
                    };
                    var rowQuestionId = SaveQuestion(rowQuestion, false, question.OptionGroupId, rowsType.Id, question.Id).Result;
                }
            }
        }