private List <string> ConvertToColumnValues(AnswerModel a)
        {
            List <string> colValues = new List <string>();

            try
            {
                colValues.Add(a.QuestionId.ToString());
                colValues.Add("'" + a.Answers + "'");
            }
            catch (Exception)
            {
                throw;
            }

            return(colValues);
        }
        public bool AddAnswer(AnswerModel amObj)
        {
            bool          isInserted = false;
            string        tableName = "Answer";
            List <string> columns = new List <string>(), colValues = ConvertToColumnValues(amObj);

            DataAccess.DataHandler dh = new DataAccess.DataHandler();

            columns.Add("questionId");
            columns.Add("Answer");

            isInserted = dh.Insert(tableName, columns, colValues);
            columns.Clear();
            colValues.Clear();

            return(isInserted);
        }
        private static AnswerModel ConvertToAnswer(Dictionary <string, string> fieldValues)
        {
            AnswerModel a = new AnswerModel();

            foreach (KeyValuePair <string, string> row in fieldValues)
            {
                switch (row.Key)
                {
                case "id":
                    try
                    {
                        a.Id = int.Parse(row.Value);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;

                case "questionId":
                    try
                    {
                        a.QuestionId = int.Parse(row.Value);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;

                case "Answer":
                    a.Answers = row.Value;
                    break;

                default:
                    break;
                }
            }
            return(a);
        }
        public void memoGeneration(Dictionary <int, List <QuestionModel> > questions, string[] questionType)
        {
            using (WordprocessingDocument doc = WordprocessingDocument.Open(outputLocation, true))
            {
                int counter = 0;

                foreach (KeyValuePair <int, List <QuestionModel> > entry in questions)
                {
                    Body docBody = doc.MainDocumentPart.Document.Body;

                    Run           run        = new Run();
                    RunProperties properties = new RunProperties();
                    properties.Bold = new Bold();
                    run.Append(properties);
                    run.Append(new Text(questionType[counter]));

                    Paragraph QuestionType = new Paragraph(run);

                    docBody.Append(QuestionType);
                    foreach (QuestionModel item in entry.Value)
                    {
                        List <AnswerModel> answers = AnswerModel.GetAnswer(null, new List <string>()
                        {
                            string.Format(" id = {0} ", item.QuestionId)
                        });

                        Paragraph questionTitle = new Paragraph(new Run(new Text("Question")));
                        Paragraph Question      = new Paragraph(new Run(new Text(item.Questions)));
                        Paragraph answerTitle   = new Paragraph(new Run(new Text("Answer")));
                        Paragraph Answer        = new Paragraph(new Run(new Text(answers[0].Answers)));
                        answers = new List <AnswerModel>();
                        docBody.Append(questionTitle);
                        docBody.Append(Question);
                        docBody.Append(answerTitle);
                        docBody.Append(Answer);
                    }
                    counter++;
                }
            }
        }
        /// <summary>
        /// This Method is for Match the Columns 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 MatchColumnsQuestions(int NumberOfQuestions, int QuestionNumber, OutcomesCollectionModel outcomesWhere, int ArrayPosition)
        {
            Random               random          = new Random();
            QuestionModel        question        = new QuestionModel();
            QuestionModel        ChoosenQuestion = new QuestionModel();
            OutcomeDetailsModel  outcomeDetails  = new OutcomeDetailsModel();
            AnswerModel          ChosenAnswer    = new AnswerModel();
            List <QuestionModel> questionsList   = new List <QuestionModel>();
            List <AnswerModel>   answersList     = new List <AnswerModel>();

            List <string>        answerWhere           = new List <string>();
            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

            questionsList = question.Select(outcomesWhere.OutcomesList);

            //fix This later.....
            foreach (QuestionModel item in questionsList)
            {
                answerWhere.Add(item.QuestionId.ToString());
            }
            answersList = AnswerModel.Select(answerWhere);

            AnswerModel[] ChoosenAnswersArray = new AnswerModel[NumberOfQuestions];
            int[]         AnswersUsed         = new int[NumberOfQuestions];
            int[]         QuestionsUsed       = new int[NumberOfQuestions];

            QuestionModel[] questionArray = new QuestionModel[NumberOfQuestions];
            int             Total         = NumberOfQuestions * 2;

            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);

                //row1.Append(cell2);

                int     LetterCounter = 0;
                Letters letters       = (Letters)LetterCounter;

                for (int i = 0; i < NumberOfQuestions; i++)
                {
                    questionArray[i] = questionsList[random.Next(questionsList.Count)];
                    ChoosenQuestion  = questionArray[i];
                    questionsList.Remove(ChoosenQuestion);
                    //QuestionsChosen[ArrayPosition].Add(ChoosenQuestion);
                    QuestionsChoosenForDi.Add(ChoosenQuestion);

                    foreach (AnswerModel item in answersList)
                    {
                        if (ChoosenQuestion.QuestionId == item.QuestionId)
                        {
                            ChoosenAnswersArray[i] = item;
                        }
                    }
                }

                for (int i = 0; i < NumberOfQuestions; i++)
                {
                    TableRow QuestionRow = 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"
                    }));

                    // this doesnt make sense and needs thought
                    //someone please check this logic



                    for (int j = 0; j < NumberOfQuestions; j++)
                    {
                        int questionRandom = random.Next(questionArray.Length);
                        if (QuestionsUsed[j] != questionRandom)
                        {
                            ChoosenQuestion  = questionArray[questionRandom];
                            QuestionsUsed[i] = questionRandom;
                        }
                    }



                    for (int j = 0; j < NumberOfQuestions; j++)
                    {
                        int answerRandom = random.Next(questionArray.Length);
                        if (AnswersUsed[j] != answerRandom)
                        {
                            ChosenAnswer   = ChoosenAnswersArray[answerRandom];
                            AnswersUsed[i] = answerRandom;
                        }
                    }
                    int       LetterCounter2 = LetterCounter + 1;
                    Paragraph Question       = new Paragraph(new Run(new Text(LetterCounter2 + "." + ChoosenQuestion.Questions)));
                    Paragraph Answer         = new Paragraph(new Run(new Text(letters + "." + ChosenAnswer.Answers)));
                    Paragraph QuestionWeight = new Paragraph(new Run(new Text(ChoosenQuestion.Weight.ToString())));

                    cell.Append(Question);
                    cell2.Append(Answer);
                    cell3.Append(QuestionWeight);
                    QuestionRow.Append(cell);
                    QuestionRow.Append(cell2);
                    QuestionRow.Append(cell3);
                    table.Append(QuestionRow);
                    letters++;
                    letters = (Letters)LetterCounter;
                }

                docBody.Append(table);
                QuestionsChosen.Add(ArrayPosition, QuestionsChoosenForDi);
            }
        }