Exemplo n.º 1
0
 public void When(SurveyQuestionAdded surveyAdded)
 {
     SurveyQuestions = SurveyQuestions.Concat(new[]
     {
         new SurveyQuestion(Guid.NewGuid(), surveyAdded.Value)
     });
 }
Exemplo n.º 2
0
        partial void SurveyQuestions_Validate(SurveyQuestion entity, EntitySetValidationResultsBuilder results)
        {
            var surveyId = entity.Survey.Id;
            var question = SurveyQuestions.Where(q => q.Survey.Id == surveyId && q.Question == entity.Question).FirstOrDefault();

            if (question != null)
            {
                results.AddEntityError("Question already exists for this survey!");
            }
        }
Exemplo n.º 3
0
        private bool NeedComment(SurveyQuestions q, int surveyOptionId)
        {
            var svOpList = q.ListSurveyOptions;

            if ((svOpList == null) || (svOpList.Count == 0))
            {
                return(false);
            }

            var m = svOpList.FirstOrDefault(x => x.Id == surveyOptionId);

            return((m != null) ? m.NeedComment : false);
        }
Exemplo n.º 4
0
        public void AddFixedQuestions(List <string> survey)
        {
            DateTime d = DateTime.Today;
            Survey   s = _db.Survey.FirstOrDefault(a => a.GenerationDate == d);

            foreach (var item in survey)
            {
                SurveyQuestions survey1 = new SurveyQuestions();
                survey1.SurveyId = s.Id;
                survey1.ChoiceA  = "Not Satisfied";
                survey1.ChoiceB  = "partially Satisfied";
                survey1.ChoiceC  = "Satisfied";
                survey1.ChoiceD  = "More than Satisfied";
                survey1.Question = item;
                _db.SurveyQuestions.Add(survey1);
                _db.SaveChanges();
            }
        }
        public async Task <bool> AddSurveyQuestions(List <Questions> questions, int surveyId)
        {
            using (UnitOfWork _unitOfWork = UnitOfWork.GenerateUnitOfWork())
            {
                try
                {
                    int order = 0;
                    List <SurveyQuestions> _surveyQuestions = new List <SurveyQuestions>();

                    foreach (var question in questions)
                    {
                        //insert into question master table
                        var query  = "insert into surveryengine.T_QUESTIONS_MASTER values (nextval('surveryengine.t_questions_master_question_id_seq'),@questionDesc, @questionTypeStringyfy,CAST(@optionValuesJson as json)) RETURNING question_id";
                        var result = await _unitOfWork.Connection.QueryAsync(query, question, transaction : _unitOfWork.Transaction);


                        SurveyQuestions _surveyQuestion = new SurveyQuestions();
                        _surveyQuestion.questionId = Convert.ToInt32(((IDictionary <string, object>)result.FirstOrDefault())["question_id"]);
                        _surveyQuestion.surveyId   = surveyId;
                        _surveyQuestion.order      = ++order;

                        _surveyQuestions.Add(_surveyQuestion);
                    }

                    //inserting into the mapping table. Map between questions and survey
                    var sql = "insert into surveryengine.t_survey_questions values (nextval('surveryengine.t_survey_questions_survey_question_id_seq'),@surveyId, @questionId,@order) RETURNING survey_question_id";

                    var rows = await _unitOfWork.Connection.ExecuteAsync(sql, _surveyQuestions);


                    _unitOfWork.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //log error
                    _unitOfWork.RollBack();
                    return(false);
                }
            }
        }
Exemplo n.º 6
0
        public void AddSurveyQuestions(List <SurveyQuestions> survey)
        {
            DateTime d = DateTime.Today;
            Survey   s = _db.Survey.FirstOrDefault(a => a.GenerationDate == d);

            foreach (var item in survey)
            {
                SurveyQuestions questions = new SurveyQuestions();
                questions.SurveyId = s.Id;
                questions.Question = item.Question /*"hhh"*/;
                questions.ChoiceA  = item.ChoiceA /*"hhh"*/;
                questions.ChoiceB  = item.ChoiceB /*"hhh"*/;
                questions.ChoiceC  = item.ChoiceC /*"hhh"*/;
                _db.SurveyQuestions.Add(questions);
                _db.SaveChanges();
            }
            //foreach (var item in survey)
            //{
            //    _db.SurveyQuestions.Add(item);
            //}
            // _db.SurveyQuestions.AddRange(survey);
        }
Exemplo n.º 7
0
        public IActionResult AddNewSurvey([FromBody] SurveyViewModel newSurvey)
        {
            string userId        = Request.Headers[Constants.UserToken];
            string decyrptstring = Security.Decrypt(userId);

            if (decyrptstring == null)
            {
                return(BadRequest());
            }

            User user = _dBContext.User.Where(x => x.UserGuid == decyrptstring).FirstOrDefault();

            if (user == null)
            {
                return(BadRequest(Messages.UserNotFoundError));
            }

            int PublishedStatusId = _dBContext.Status.Where(x => x.Statusname == "Published").Select(x => x.Statusid).FirstOrDefault();

            Survey s = _mapper.Map <Survey>(newSurvey);

            s.StatusId    = PublishedStatusId;
            s.CreatedDate = DateTime.UtcNow;
            s.CreatedBy   = user.Userid;
            s.Enddate     = DateTime.UtcNow.AddYears(1);

            _dBContext.Survey.Add(s);
            _dBContext.SaveChanges();

            List <SurveyQuestions> qlist = new List <SurveyQuestions>();
            int qcount = 0;

            foreach (var item in newSurvey.SurveyQuestions)
            {
                SurveyQuestions question = _mapper.Map <SurveyQuestions>(item);
                question.SurveyId             = s.Surveyid;
                question.CreatedBy            = Convert.ToInt32(s.CreatedBy);
                question.CreatedDate          = DateTime.UtcNow;
                question.StatusId             = PublishedStatusId;
                question.QuestionDisplayOrder = qcount;
                qlist.Add(question);
                qcount++;
            }

            _dBContext.SurveyQuestions.AddRange(qlist);
            _dBContext.SaveChanges();


            for (int i = 0; i < qlist.Count; i++)
            {
                int qid     = qlist[i].SurveyQuestionId;
                var options = newSurvey.SurveyQuestions[i].Options;
                List <SurveyQuestionOptions> qoplist = new List <SurveyQuestionOptions>();
                if (options != null)
                {
                    foreach (var item in options)
                    {
                        SurveyQuestionOptions qop = new SurveyQuestionOptions();
                        qop.SurveyQuestionId = qid;
                        qop.OptionKey        = item.Key;
                        qop.OptionValue      = Convert.ToString(item.Value);
                        qop.CreatedBy        = Convert.ToInt32(s.CreatedBy);
                        qop.CreatedDate      = DateTime.UtcNow;
                        qoplist.Add(qop);
                    }
                    _dBContext.SurveyQuestionOptions.AddRange(qoplist);
                }

                _dBContext.SaveChanges();
            }

            return(GetSurvey(s.Surveyid));
        }
Exemplo n.º 8
0
        public IActionResult UserSurveyReports(string surveyGuid, int surveyQuestionId)
        {
            SurveyMetrics metric = new SurveyMetrics(_dBContext, _mapper);
            string        userId = Request.Headers[Constants.UserToken];
            User          user;

            _memoryCache.TryGetValue(userId, out user);
            if (user == null)
            {
                return(Unauthorized(Messages.UserNotFoundError));
            }

            Survey survey = _dBContext.Survey.Where(x => x.CreatedBy == user.Userid && x.SurveyGuid == surveyGuid).FirstOrDefault();

            if (survey == null)
            {
                return(BadRequest(Messages.SurveyNotFoundError));
            }

            SurveyQuestions surveyQuestion = _dBContext.SurveyQuestions.Where(x => x.StatusId != (int)EnumStatus.Deleted && x.SurveyId == survey.Surveyid && x.SurveyQuestionId == surveyQuestionId).ToList().FirstOrDefault();

            List <QuestionType> questionType = _dBContext.QuestionType.ToList();

            SurveySingleMetricViewModel surveyMetric   = new SurveySingleMetricViewModel();
            QuestionMetricViewModel     questionMetric = new QuestionMetricViewModel();
            var type = questionType.Where(x => x.TypeId == surveyQuestion.TypeId).Select(x => x.TypeCode).FirstOrDefault();

            switch (type)
            {
            case "radiobuttons":
                questionMetric = metric.forCountAndAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "multiple":
                questionMetric = metric.forCountAndAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "imageradiobuttons":
                questionMetric = metric.forCountAndAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "imagemultiple":
                questionMetric = metric.forCountAndAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "slider":
                questionMetric = metric.forSliderAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "rangeslider":
                questionMetric = metric.forSliderAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "starrating":
                questionMetric = metric.forStarRatingAverage(surveyQuestion.SurveyQuestionId);
                break;

            case "multiplerating":
                questionMetric = metric.forMultipleStarRatings(surveyQuestion.SurveyQuestionId);
                break;

            case "customrating":
                questionMetric = metric.forCustomRatings(surveyQuestion.SurveyQuestionId);
                break;

            default:
                break;
            }
            questionMetric.QuestionType            = type;
            questionMetric.originalQuestionOptions = _dBContext.SurveyQuestionOptions.Where(x => x.SurveyQuestionId == surveyQuestion.SurveyQuestionId).ToList();
            surveyMetric.Title       = survey.Welcometitle;
            surveyMetric.Description = survey.Welcomedescription;
            surveyMetric.logo        = survey.Welcomeimage;
            surveyMetric.Question    = questionMetric;
            return(Ok(surveyMetric));
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="question"></param>
        /// <param name="options"></param>
        /// <param name="answerList"></param>
        /// <param name="tableOptions"></param>
        /// <param name="questionIndex"></param>
        private void PopulateQuestion(SurveyQuestions question, HtmlTable tableOptions, int questionIndex)
        {
            var rowQuestion       = new HtmlTableRow();
            var cellQuestion      = new HtmlTableCell();
            var cellQuestionTitle = new HtmlTableCell();
            var strongQuestion    = new HtmlGenericControl();

            rowQuestion.Controls.Add(cellQuestionTitle);
            rowQuestion.Controls.Add(cellQuestion);
            tableOptions.Controls.Add(rowQuestion);

            cellQuestionTitle.Controls.Add(strongQuestion);

            if (question == null || question.ListSurveyOptions.Count == 0)
            {
                cellQuestion.Controls.Add(new Label {
                    Text = "QuestionsNotAvailableText"
                });
            }
            else
            {
                //cellQuestionTitle.Controls.Add(new HtmlGenericControl("BR"));
                cellQuestion.Controls.Add(new Label {
                    Text = question.QuestionText
                });
                cellQuestion.Attributes.Add("class", "question-title");
                //cellQuestion.Controls.Add(new HtmlGenericControl("BR"));
                var strongOption = new HtmlGenericControl();

                var cellOptionTitle = new HtmlTableCell();

                cellOptionTitle.Controls.Add(strongOption);

                var isFirstOption = true;

                foreach (var option in question.ListSurveyOptions)
                {
                    var rowOption       = new HtmlTableRow();
                    var cellOption      = new HtmlTableCell();
                    var cellOptionLabel = new HtmlTableCell();

                    if (isFirstOption)
                    {
                        rowOption.Controls.Add(cellOptionTitle);
                        isFirstOption = false;
                    }
                    else
                    {
                        rowOption.Controls.Add(cellOptionLabel);
                    }
                    if (option.Type == QuestionType.Feedback)
                    {
                        cellOption.Controls.Add(
                            new TextBox
                        {
                            ID = string.Format("txtOption{0}", option.Id),
                        });
                    }
                    else if (option.Type == QuestionType.MultipleChoice)
                    {
                        var ui = new CheckBox
                        {
                            Text = option.OptionText,
                            ID   = string.Format("chkOption{0}", option.Id),
                        };
                        ui.Attributes["onChange"] = "OnSurveyOptionChange($(this));";

                        cellOption.Controls.Add(ui);

                        cellOption.Attributes.Add("class", "check-option");

                        if (option.NeedComment)
                        {
                            AppendNeedCommentUI(cellOption, option, ui);
                        }
                    }
                    else
                    {
                        var ui = new RadioButton
                        {
                            Text      = option.OptionText,
                            ID        = string.Format("rdOption{0}", option.Id),
                            GroupName = string.Format("optionsQuestion{0}", question.Id),
                            Checked   = false
                        };
                        ui.Attributes["onChange"] = "OnSurveyOptionChange($(this));";

                        cellOption.Controls.Add(ui);

                        if (option.NeedComment)
                        {
                            AppendNeedCommentUI(cellOption, option, ui);
                        }
                    }

                    rowOption.Controls.Add(cellOption);

                    tableOptions.Controls.Add(rowOption);
                }

                var rowSpace  = new HtmlTableRow();
                var cellSpace = new HtmlTableCell {
                    ColSpan = 2
                };

                cellSpace.Controls.Add(new HtmlGenericControl("HR"));

                rowSpace.Controls.Add(cellSpace);
                tableOptions.Controls.Add(rowSpace);
            }
        }
Exemplo n.º 10
0
        private void CaptureComment(SelectionDetail dataObject, PlaceHolder uiObject, SurveyQuestions q, int surveyOptionId)
        {
            if (!NeedComment(q, surveyOptionId))
            {
                return;
            }

            var uiComment = uiObject.FindControl(Id_NeedComment_Prefix + surveyOptionId) as TextBox;

            if (uiComment == null)
            {
                return;
            }

            var txt = uiComment.Text;

            if (string.IsNullOrWhiteSpace(txt))
            {
                return;
            }

            dataObject.Feedback = txt.Trim();
        }
Exemplo n.º 11
0
 public async Task <int> QuestionTransaction(SurveyQuestions data, char action)
 {
     return(await _survey.QuestionTransaction(data, action));
 }
Exemplo n.º 12
0
 public async Task <int> QuestionTransaction(SurveyQuestions data, char action)
 {
     return(await _adapterPattern.SingleTransaction <SurveyQuestions, int>(data, "usp_SurveyQuestions_Transaction", action, DataConfiguration.instanceCore));
 }
Exemplo n.º 13
0
 public ActionResult Create(SurveyQuestions surveyQuestions)
 {
     unitOfWork.SurveyQuestions.AddQuestion(surveyQuestions);
     unitOfWork.SaveChanges();
     return(RedirectToAction("Index"));
 }