internal int CalculateAnswers(ChoseQuestionsVm choseQuestions, string optionOne, string optionTwo) { var numberOfTwo = _questionContext.Answers.Where(x => x.Value == optionTwo && x.QuestionId == choseQuestions.QuestionTwo.QuestionId).Select(x => x.PersonId).ToList(); var numberofOne = _questionContext.Answers.Where(x => x.Value == optionOne && x.QuestionId == choseQuestions.QuestionOne.QuestionId).Select(x => x.PersonId).ToList(); var compareLists = numberOfTwo.Intersect(numberofOne).Count(); return(compareLists); }
public IActionResult ChoseQuestions(Guid marketResearchId) { var listOfQuestions = _dataAccessQuestions.GetQuestionsForMarketResearch(marketResearchId); var questionList = new List <SelectListItem>(); foreach (var item in listOfQuestions) { questionList.Add(new SelectListItem { Text = $"Fråga {item.Question.QuestionNumber.ToString()}. {item.Question.QuestionType}. {item.Question.ActualQuestion}", Value = item.QuestionId.ToString() }); } var viewModelChoseQuestion = new ChoseQuestionsVm(); viewModelChoseQuestion.QuestionList = questionList; return(View(viewModelChoseQuestion)); }
public IActionResult ShowQuestionComparison(ChoseQuestionsVm choseQuestions) { var questionOneData = _dataAccessQuestions.GetDataForQuestion(choseQuestions.QuestionOne); var questionTwoData = _dataAccessQuestions.GetDataForQuestion(choseQuestions.QuestionTwo); var questionHeadingsOne = _dataAccessQuestions.GetHeadings(choseQuestions.QuestionOne); var questionHeadingsTwo = _dataAccessQuestions.GetHeadings(choseQuestions.QuestionTwo); ShowQuestionComparisonVm viewModelShowComparison = new ShowQuestionComparisonVm(); bool[] binaryOptions = { true, false }; List <List <int> > dataForTable = new List <List <int> >(); if (questionOneData[0] == QuestionTypes.Binärfråga) { foreach (bool optionOne in binaryOptions) { string[] headingsOne = questionHeadingsOne[0].Split('-'); if (questionTwoData[0] == QuestionTypes.Binärfråga) { string[] headingsTwo = questionHeadingsTwo[0].Split('-'); List <int> arrayList = new List <int>(); foreach (bool optionTwo in binaryOptions) { int numberOfAnswers = _dataAccessQuestions.CalculateAnswers(choseQuestions, optionOne.ToString(), optionTwo.ToString()); arrayList.Add(numberOfAnswers); } viewModelShowComparison.HeadingsVertical = headingsOne; viewModelShowComparison.HeadingsHorizontal = headingsTwo; dataForTable.Add(arrayList); } else { List <int> arrayList = new List <int>(); foreach (string headingTwo in questionHeadingsTwo) { int numberOfAnswers = _dataAccessQuestions.CalculateAnswers(choseQuestions, optionOne.ToString(), headingTwo); arrayList.Add(numberOfAnswers); } viewModelShowComparison.HeadingsVertical = headingsOne; viewModelShowComparison.HeadingsHorizontal = questionHeadingsTwo.ToArray(); dataForTable.Add(arrayList); } } } else { foreach (string headingOne in questionHeadingsOne) { if (questionTwoData[0] == QuestionTypes.Binärfråga) { string[] headingsTwo = questionHeadingsTwo[0].Split('-'); List <int> arrayList = new List <int>(); foreach (bool optionTwo in binaryOptions) { int numberOfAnswers = _dataAccessQuestions.CalculateAnswers(choseQuestions, headingOne, optionTwo.ToString()); arrayList.Add(numberOfAnswers); } viewModelShowComparison.HeadingsVertical = questionHeadingsOne.ToArray(); viewModelShowComparison.HeadingsHorizontal = headingsTwo; dataForTable.Add(arrayList); } else { List <int> arrayList = new List <int>(); foreach (string headingTwo in questionHeadingsTwo) { int numberOfAnswers = _dataAccessQuestions.CalculateAnswers(choseQuestions, headingOne, headingTwo); arrayList.Add(numberOfAnswers); } viewModelShowComparison.HeadingsVertical = questionHeadingsOne.ToArray(); viewModelShowComparison.HeadingsHorizontal = questionHeadingsTwo.ToArray(); dataForTable.Add(arrayList); } } } viewModelShowComparison.DataArrayForComparison = dataForTable; return(View(viewModelShowComparison)); }