private IList <SurveyAnswerItemViewModel> CreateChoices( SurveyQuestionModel q, IList <SurveyQuestionAnswerChoiceResponseModel> previousAnswers) { // Create the view model for each answer item, potentially using an existing answer response model var choices = new List <SurveyAnswerItemViewModel>(q.AnswerChoices.Count); foreach (var choice in q.AnswerChoices.OrderBy(a => a.AnswerChoiceNum, StringComparer.Ordinal)) { var previousAnswer = previousAnswers.SingleOrDefault(a => a.AnswerChoiceID == choice.AnswerChoiceID); choices.Add(previousAnswer != null ? new SurveyAnswerItemViewModel(choice, previousAnswer, true) : new SurveyAnswerItemViewModel( choice, new SurveyQuestionAnswerChoiceResponseModel { QuestionID = q.QuestionID, AnswerChoiceID = choice.AnswerChoiceID, })); } // Add a listener for when the answer choice is selected foreach (var choice in choices) { // We reuse the PropertyChanged event since it's already wired up correctly choice.PropertyChanged += (sender, e) => { // Check to make sure it was the IsSelected property that changed if (e.PropertyName == nameof(SurveyAnswerItemViewModel.IsSelected)) { // If multiple answers are not allowed, unselect any other selected choices if (!q.AllowMultipleAnswers && choice.IsSelected) { foreach (var otherChoice in choices) { if (otherChoice != choice) { otherChoice.IsSelected = false; } } } // If the choice is selected, add it to the response model if (choice.IsSelected) { _viewModel.AddAnswer(choice.Answer); } // Else when the choice is unselected, remove it from the response model else { _viewModel.RemoveAnswer(choice.Answer); } _viewModel.UpdateCommands(); } }; } return(choices); }
/// <summary> /// /// </summary> /// <returns></returns> public List <SurveyQuestionModel> GetAllQuestions() { SurveyQuestionModel model = new SurveyQuestionModel(); using (LBCData context = new LBCData(ConnectionHelper.getConnectionString())) { var lst = from q in context.LBC_SURVEY_QUESTIONS join a in context.LBC_SURVEY_QUESTION_ANSWER on q.QUESTION_ID equals a.QUESTION_ID orderby q.QUESTION_ID ascending select new SurveyQuestionModel(); return(lst.ToList <SurveyQuestionModel>()); } }
public List <SurveyQuestionModel> GetReportQuestions() { SurveyQuestionModel model = new SurveyQuestionModel(); using (LBCData context = new LBCData(ConnectionHelper.getConnectionString())) { var lst = from q in context.LBC_SURVEY_QUESTIONS orderby q.QUESTION_ID ascending select new SurveyQuestionModel { QUESTION_ID = q.QUESTION_ID, QUESTION_DESC = q.QUESTION_DESC }; return(lst.ToList <SurveyQuestionModel>()); } }
public static SurveyModel ConvertToModel(Survey survey) { SurveyModel model = new SurveyModel() { SurveyID = survey.ID, Name = survey.Name, Description = survey.Description, IntroText = survey.IntroText, Version = survey.Version, LastUpdated = survey.LastUpdated }; foreach (SurveyQuestion sq in survey.SurveyQuestions) { SurveyQuestionModel qm = new SurveyQuestionModel() { QuestionID = sq.Question_ID, QuestionNum = sq.QuestionNum, QuestionText = sq.Question.QuestionText, QuestionHelpText = sq.Question.ClarificationText, AllowMultipleAnswers = sq.Question.AllowMultipleAnswers, WellKnownQuestion = sq.Question.WellKnownQuestion }; foreach (SurveyAnswerChoice ac in sq.AnswerChoices) { SurveyQuestionAnswerChoiceModel acm = new SurveyQuestionAnswerChoiceModel() { AnswerChoiceID = ac.AnswerChoice_ID, AnswerChoiceNum = ac.AnswerChoiceNum, AnswerChoiceText = ac.AnswerChoice.AnswerText, AdditionalAnswerDataFormat = ac.AnswerChoice.AdditionalAnswerDataFormat, NextQuestionID = (ac.EndSurvey) ? SurveyQuestionAnswerChoiceModel.END_SURVEY : ac.NextSurveyQuestion?.Question_ID, EndSurvey = ac.EndSurvey }; qm.AnswerChoices.Add(acm); } model.Questions.Add(qm); } return(model); }
public bool Update(SurveyQuestionModel model) { return(_repository.Update(model)); }
public SurveyQuestionModel Create(SurveyQuestionModel model) { return(_repository.Create(model)); }