public ActionResult CustomerAssessment(QuestionOnePost question) { // Get Report string companyName = string.Empty, address = string.Empty, contactName = string.Empty; var userInfo = new Repository <Organization>(); var user = userInfo.Filter(q => q.Id == this.UserId).FirstOrDefault(); if (user != null) { companyName = user.Name; address = user.Address; contactName = user.ContactName; } if (question.hdnaction != string.Empty && (question.hdnaction.Contains("PDF") || question.hdnaction.Contains("CSV"))) { var level = question.hdnaction.Split('-')[1]; if (question.hdnaction.Contains("PDF")) { return(PdfExport(companyName, address, contactName, level)); } else { return(CsvExport(companyName, address, contactName, level)); } } else { GroupQuiz groupQuiz = null; int groupId = int.Parse(question.QInfo); if (question.hdnaction == "Previous") { groupId = groupId - 1; if (groupId <= 0) { groupId = 1; } } else { groupId = groupId + 1; } this.groupQuizManager = new GroupQuizManager(this.UserId); this.groupQuizManager.AllQuestions = (List <GroupQuiz>)Session["AllGroupQuestions"]; if (this.groupQuizManager.MoveToNextGroup(groupId)) { groupQuiz = this.groupQuizManager.LoadQuiz(groupId); } else { groupQuiz = this.groupQuizManager.LoadQuiz(--groupId); } return(PartialView("QuizGroupPartial", groupQuiz)); } }
public ActionResult QuizGroup(string id = null) { GroupQuiz groupQuiz = null; if (string.IsNullOrWhiteSpace(id)) { groupQuiz = GetGroupQuiz(); } else { groupQuiz = GetLastGroupQuiz(); } ViewBag.AssessmentName = groupQuiz.AssessmentName; return(View(groupQuiz)); }
public ActionResult CustomerAssessmentReport(QuestionOnePost question) { //PDF-1-Level 1 if (question.hdnaction != string.Empty && (question.hdnaction.Contains("PDF") || question.hdnaction.Contains("CSV"))) { var values = question.hdnaction.Split('-'); if (question.hdnaction.Contains("PDF")) { return(PdfExport(int.Parse(values[1]), values[2])); } else { return(CsvExport(int.Parse(values[1]), values[2])); } } else { var groupQuizManager = new GroupQuizManager(question.UserId); var listOfGroup = groupQuizManager.GetAllQuestions(question.Level); groupQuizManager.AllQuestions = listOfGroup; GroupQuiz groupQuiz = new GroupQuiz(); int groupId = int.Parse(question.QInfo); if (question.hdnaction == "Previous") { groupId = groupId - 1; if (groupId <= 0) { groupId = 1; } } else { if (listOfGroup.Count > groupId) { groupId = groupId + 1; } } if (groupQuizManager.MoveToNextGroup(groupId)) { groupQuiz = groupQuizManager.LoadQuiz(groupId); } groupQuiz.UserId = question.UserId; return(PartialView("~/Views/ManageUser/QuizGroupPartial.cshtml", groupQuiz)); } }
public GroupQuiz LoadQuiz(int groupId) { var nullgroup = new GroupQuiz(); nullgroup.listOfQuestions = new List <QuestionAnswer>(); var allGroup = AllGroupQuiz(); if (allGroup.Count == 0) { return(nullgroup); } var currentGroup = allGroup.Where(q => q.UIGroupId == groupId).First(); return(GetCountDetails(allGroup, currentGroup)); }
private GroupQuiz GetCountDetails(List <GroupQuiz> allGroupQuiz, GroupQuiz currentQuiz) { int answeredCount = 0; int noQuestions = 0; allGroupQuiz.ForEach(q => noQuestions += q.listOfQuestions.Count()); currentQuiz.NoOfQuestions = noQuestions; currentQuiz.NoOfGroups = allGroupQuiz.Count(); allGroupQuiz.ForEach(v => { v.listOfQuestions.ForEach(s => { if (s.AnswerChoices.Any(t => t.IsChecked)) { answeredCount++; } }); }); currentQuiz.NoOfCompletedQuestions = answeredCount; return(currentQuiz); }
public List <GroupQuiz> GetAllQuestions(string level = null) { var listOfGroupQuestions = new List <GroupQuiz>(); var uInfo = new Repository <Organization>(); int sectorValue = int.Parse(Utilities.SectorValue); var userSectorId = uInfo.Filter(q => q.Id == this.UserId).FirstOrDefault(); var assessmentDetails = uInfo.AssessmentContext.assessments.Where(q => q.Sector == userSectorId.SectorId).FirstOrDefault(); if (assessmentDetails == null || assessmentDetails.Sector == 0) { assessmentDetails = uInfo.AssessmentContext.assessments.Where(q => q.Sector == sectorValue).FirstOrDefault(); } //var details = uInfo.AssessmentContext.UserInfo.Join(uInfo.AssessmentContext.assessments, u => u.SectorId, a => a.Sector, (u, a) => new { u, a }).Where(q=> q.u.Id == UserId).FirstOrDefault(); var questionIds = new List <int>(); if (level == null) { questionIds = uInfo.AssessmentContext.assessmentLevelMappings.Where(q => q.AssessmentId == assessmentDetails.Id && q.Level == userSectorId.CurrentAssignmentType).Select(q => q.QuestionId).ToList(); } else { questionIds = uInfo.AssessmentContext.assessmentLevelMappings.Where(q => q.AssessmentId == assessmentDetails.Id && q.Level == level).Select(q => q.QuestionId).ToList(); } var lQuestions = uInfo.AssessmentContext.questions.Where(q => questionIds.Contains(q.Id)).GroupBy(q => q.GroupId).Select(q => new { Questions = q.ToList(), Type = q.Key }).OrderBy(t => t.Type).ToList(); int i = 1; int slno = 1; lQuestions.ForEach(t => { var listOfGroupQuiz = new GroupQuiz(); listOfGroupQuiz.UIGroupId = i; listOfGroupQuiz.GroupId = t.Type; listOfGroupQuiz.GroupText = uInfo.AssessmentContext.groups.Where(q => q.Id == t.Type).FirstOrDefault().Name; listOfGroupQuiz.AssessmentName = assessmentDetails.Name; listOfGroupQuiz.listOfQuestions = new List <QuestionAnswer>(); int k = 1; t.Questions.ForEach(v => { var question = new QuestionAnswer(); question.Questions = new QuestionQuiz() { QuestionCode = "Q" + k, QuestionId = v.Id, QuestionText = v.QuestionText, Mandatory = v.Mandatory, Slno = slno }; var answerChoice = new List <AnswerChoice>(); answerChoice.Add(new AnswerChoice() { AnswerChoiceId = 1, Choices = v.Option1 }); answerChoice.Add(new AnswerChoice() { AnswerChoiceId = 2, Choices = v.Option2 }); answerChoice.Add(new AnswerChoice() { AnswerChoiceId = 3, Choices = v.Option3 }); answerChoice.Add(new AnswerChoice() { AnswerChoiceId = 4, Choices = v.Option4 }); answerChoice.Add(new AnswerChoice() { AnswerChoiceId = 5, Choices = v.Option5 }); question.AnswerChoices = answerChoice; listOfGroupQuiz.listOfQuestions.Add(question); k++; slno++; }); i++; listOfGroupQuestions.Add(listOfGroupQuiz); }); return(listOfGroupQuestions); }