private List <string> ConvertToColumnValues(QuestionChoicesModel qc) { List <string> colValues = new List <string>(); try { colValues.Add(qc.QuestionId.ToString()); colValues.Add("'" + qc.Choice + "'"); } catch (Exception) { throw; } return(colValues); }
private static QuestionChoicesModel ConvertToQuestionChoice(Dictionary <string, string> fieldValues) { QuestionChoicesModel qc = new QuestionChoicesModel(); foreach (KeyValuePair <string, string> row in fieldValues) { switch (row.Key) { case "id": try { qc.ChoiceId = int.Parse(row.Value); } catch (Exception) { throw; } break; case "QuestionID": try { qc.QuestionId = int.Parse(row.Value); } catch (Exception) { throw; } break; case "Choice": qc.Choice = row.Value; break; default: break; } } return(qc); }
/// <summary> /// This Method is for multiple choice of the exam paper /// </summary> /// <param name="NumberOfQuestions">This is the number of questions under the multiple choice section</param> /// <param name="QuestionNumber">the number of the question in the exam</param> public void CreateMultipleChoice(int NumberOfQuestions, int QuestionNumber, OutcomesCollectionModel outcomesWhere, int ArrayPosition) { int Counter = 1; int Total = NumberOfQuestions * 2; string[] QuestionsUsed = new string[NumberOfQuestions]; // i cant remember what i wanted here Random random = new Random(); QuestionModel question = new QuestionModel(); QuestionChoicesModel questionChoice = new QuestionChoicesModel(); QuestionModel ChoosenQuestion = new QuestionModel(); List <QuestionModel> QuestionsChoosenForDi = new List <QuestionModel>(); //Dont forget to include a where clause for the questions and choices for outcomes chosen and types for the questions List <QuestionModel> questionList = question.Select(outcomesWhere.OutcomesList); //foreach (Question item in questionList) //{ // List<string> where = new List<string>() { string.Format("id = {0}", item.QuestionId) }; //question id for the where clause // List<QuestionChoice> questionChoiceList = questionChoice.GetQuestionChoice(null, where); //} using (WordprocessingDocument doc = WordprocessingDocument.Open(outputLocation, true)) { Body docBody = doc.MainDocumentPart.Document.Body; Table table = new Table(); TableRow row1 = new TableRow(); TableRow row2 = new TableRow(); TableCell cell = new TableCell(); cell.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); TableCell cell2 = new TableCell(); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "5000" })); TableCell cell3 = new TableCell(); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "500" })); Paragraph paragraph = new Paragraph(new Run(new Text(string.Format("Question {0}", QuestionNumber)))); Paragraph paragraph1 = new Paragraph(new Run(new Text(string.Format("[{0}]", Total)))); cell.Append(paragraph); cell3.Append(paragraph1); row1.Append(cell); row1.Append(cell2); row1.Append(cell3); table.Append(row1); // this loop is for the creation of a question and the choices for the question for (int i = 0; i < NumberOfQuestions; i++) { TableRow tableRow = new TableRow(); cell = new TableCell(); cell2 = new TableCell(); cell.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); cell3 = new TableCell(); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2500" })); ChoosenQuestion = questionList[random.Next(questionList.Count)]; questionList.Remove(ChoosenQuestion); Paragraph Question = new Paragraph(new Run(new Text(Counter + "." + ChoosenQuestion.Questions))); Paragraph QuestionWeight = new Paragraph(new Run(new Text(ChoosenQuestion.Weight.ToString()))); //QuestionsChosen[ArrayPosition].Add(ChoosenQuestion); QuestionsChoosenForDi.Add(ChoosenQuestion); cell.Append(Question); cell3.Append(QuestionWeight); tableRow.Append(cell); tableRow.Append(cell2); tableRow.Append(cell3); table.Append(tableRow); TableRow tableRow2 = new TableRow(); List <string> where = new List <string>() { string.Format("QuestionID = {0}", ChoosenQuestion.QuestionId) }; List <QuestionChoicesModel> questionChoiceList = questionChoice.GetQuestionChoice(null, where); // this to select a letter according to the number of the choice int LetterCounter = 0; Letters letters = (Letters)LetterCounter; //this will write out the choices for a question foreach (QuestionChoicesModel item in questionChoiceList) { cell = new TableCell(); cell.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "500" })); cell2 = new TableCell(); tableRow2 = new TableRow(); Paragraph Choices = new Paragraph(new Run(new Text(" " + letters.ToString() + "." + item.Choice))); LetterCounter++; cell2.Append(Choices); tableRow2.Append(cell); tableRow2.Append(cell2); table.Append(tableRow2); letters = (Letters)LetterCounter; } Counter++; } docBody.Append(table); QuestionsChosen.Add(ArrayPosition, QuestionsChoosenForDi); } }