public IActionResult SurveyDetail(Guid guid) { using (_dbContext) { var response = ResponseModelFactory.CreateResultInstance; var query = _dbContext.Survey.FirstOrDefault(x => x.SurveyUuid == guid); if (query == null) { response.SetFailed("获取问卷失败"); } SurveyDetail entity = new SurveyDetail(); entity.SurveyUuid = query.SurveyUuid; entity.Headline = query.Headline; entity.Type = query.Type; entity.SurveyQuestionDetail = new List <SurveyQuestionDetail>(); var question = _dbContext.SurveyQuestions.Where(x => x.SurveyUuid == query.SurveyUuid && x.IsDelete == 0).OrderBy(x => x.Id); foreach (var item in question) { SurveyQuestionDetail questiondetail = new SurveyQuestionDetail(); questiondetail.QuestionTitle = item.QuestionTitle; questiondetail.IsMuti = item.IsMuti; questiondetail.QuestionType = item.QuestionType; questiondetail.SurveyQuestionItemDetail = new List <SurveyQuestionItemDetail>(); if (item.QuestionType == 0) { var questionitem = _dbContext.SurveyQuestionsItems.Where(x => x.SurveyQuestionsUuid == item.SurveyQuestionsUuid && x.IsDelete == 0).OrderBy(x => x.Id); foreach (var item1 in questionitem) { SurveyQuestionItemDetail questionitemdetail = new SurveyQuestionItemDetail(); questionitemdetail.Optionts = item1.Optionts; questionitemdetail.QuestionStr = item1.QuestionStr; questionitemdetail.checkbox = false; questionitemdetail.disabled = false; questiondetail.SurveyQuestionItemDetail.Add(questionitemdetail); } } entity.SurveyQuestionDetail.Add(questiondetail); } response.SetData(entity); return(Ok(response)); } }
public IActionResult SurveyDetail(Guid guid) { using (_dbContext) { var response = ResponseModelFactory.CreateResultInstance; var query = _dbContext.Survey.FirstOrDefault(x => x.SurveyUuid == guid); if (query == null) { response.SetFailed("获取问卷失败"); } SurveyDetail entity = new SurveyDetail(); entity.SurveyUuid = query.SurveyUuid; entity.Headline = query.Headline; entity.Type = query.Type; entity.SurveyQuestionDetail = new List <SurveyQuestionDetail>(); var answer = _dbContext.SurveyAnswer.Where(x => x.SurveyUuid == query.SurveyUuid).Select(x => x.AnswerStr).ToList(); List <AnswerStatisticModel> AnswerStatistic = new List <AnswerStatisticModel>(); foreach (var item in answer) { AnswerStatisticModel Statistic = new AnswerStatisticModel(); string[] itemstr = item.Split("||"); List <AnswerListViewModel> answerlist = new List <AnswerListViewModel>(); for (int i = 0; i < itemstr.Length; i++) { AnswerListViewModel answercontent = new AnswerListViewModel(); answercontent.Content = itemstr[i]; answercontent.Multiple = new List <string>(itemstr[i].Split(',')); answerlist.Add(answercontent); } Statistic.answerlist = answerlist; AnswerStatistic.Add(Statistic); } var question = _dbContext.SurveyQuestions.Where(x => x.SurveyUuid == query.SurveyUuid && x.IsDelete == 0).OrderBy(x => x.Id); int index = 0; foreach (var item in question) { SurveyQuestionDetail questiondetail = new SurveyQuestionDetail(); questiondetail.QuestionTitle = item.QuestionTitle; questiondetail.IsMuti = item.IsMuti; questiondetail.QuestionType = item.QuestionType; questiondetail.SurveyQuestionItemDetail = new List <SurveyQuestionItemDetail>(); //选择题 if (item.QuestionType == 0) { var questionitem = _dbContext.SurveyQuestionsItems.Where(x => x.SurveyQuestionsUuid == item.SurveyQuestionsUuid && x.IsDelete == 0).OrderBy(x => x.Id); foreach (var item1 in questionitem) { SurveyQuestionItemDetail questionitemdetail = new SurveyQuestionItemDetail(); questionitemdetail.Optionts = item1.Optionts; questionitemdetail.QuestionStr = item1.QuestionStr; questionitemdetail.checkbox = false; questionitemdetail.disabled = false; int chosenum = 0; //单选 if (item.IsMuti == 0) { for (int j = 0; j < AnswerStatistic.Count; j++) { if (AnswerStatistic[j].answerlist[index].Content == item1.Optionts) { chosenum++; } } } //多选 else if (item.IsMuti == 1) { for (int j = 0; j < AnswerStatistic.Count; j++) { if (AnswerStatistic[j].answerlist[index].Multiple.Contains(item1.Optionts)) { chosenum++; } } } questionitemdetail.num = chosenum; questiondetail.SurveyQuestionItemDetail.Add(questionitemdetail); } } //主观题 else if (item.QuestionType == 1) { string str = ""; for (int j = 0; j < AnswerStatistic.Count; j++) { if (AnswerStatistic[j].answerlist[index].Content != "") { str += AnswerStatistic[j].answerlist[index].Content + " "; } } questiondetail.SubText = str; } entity.SurveyQuestionDetail.Add(questiondetail); index++; } response.SetData(entity); return(Ok(response)); } }