コード例 #1
0
        /// <summary>
        /// Returns A subtopic DTO objects based upon
        /// the id given.
        /// </summary>
        /// <param name="SubtopicID"></param>
        /// <returns></returns>
        public SubTopic getSubtopic(int SubtopicID)
        {
            SubTopic newSubtopic = new SubTopic();

            newSubtopic = Mapper.Map <SubTopic>(dbSubtopics.Where(x => x.Subtopic_ID == SubtopicID).First());
            return(newSubtopic);
        }
コード例 #2
0
        /// <summary>
        /// Returns all the exam Questions
        /// This includes everything attached to an exam Questions
        /// such as all the categories
        /// and all the Questions attached to that exam Question
        /// And all the answes attached to the Questions.
        /// </summary>
        /// <returns></returns>
        public List <ExamQuestion> GetAllExamQuestion()
        {
            AutoMapperConfiguration.Configure();
            List <ExamQuestion> result = new List <ExamQuestion>();


            var dbExamQuestion = db.ExamQuestion.ToList();
            var dbCategories   = db.Categories.ToList();
            var dbSubtopic     = db.Subtopic.ToList();
            var dbCatSub       = db.Categories_Subtopic.ToList();
            var dbQuestExam    = db.ExamQuestionList.ToList();
            var dbQuestion     = db.Question.ToList();



            for (int i = 0; i < dbExamQuestion.Count; i++)
            {
                ExamQuestion question = new ExamQuestion();
                question.ExamQuestionID                = dbExamQuestion.ElementAt(i).ExamQuestionID;
                question.ExamQuestionName              = dbExamQuestion.ElementAt(i).ExamQuestionName;
                question.PKID                          = dbExamQuestion.ElementAt(i).PKID;
                question.QuestionType.PKID             = dbExamQuestion.ElementAt(i).QuestionTypeID;
                question.QuestionType.QuestionTypeName = dbExamQuestion.ElementAt(i).QuestionType.QuestionTypeName;
                for (int j = 0; j < dbExamQuestion.ElementAt(i).ExamQuestion_Categories.Count; j++)
                {
                    Category cat = new Category();


                    cat.Categories_ID   = dbExamQuestion.ElementAt(i).ExamQuestion_Categories.ElementAt(j).Categories_ID;
                    cat.Categories_Name = dbCategories.Where(s => s.Categories_ID == dbExamQuestion.ElementAt(i).ExamQuestion_Categories.ElementAt(j).Categories_ID).First().Categories_Name;

                    List <int> listofSub = dbCatSub.Where(s => s.Categories_ID == cat.Categories_ID).Select(s => s.Subtopic_ID).ToList();
                    for (int k = 0; k < listofSub.Count(); k++)
                    {
                        var      subtopic = dbSubtopic.Where(s => s.Subtopic_ID == listofSub.ElementAt(k));
                        SubTopic sub      = new SubTopic();
                        sub.Subtopic_ID   = subtopic.ElementAt(0).Subtopic_ID;
                        sub.Subtopic_Name = subtopic.ElementAt(0).Subtopic_Name;
                        cat.subtopics.Add(sub);
                    }
                    question.ExamQuestion_Categories.Add(cat);
                }

                List <int>   QuestionIDs = dbQuestExam.Where(s => s.ExamQuestionID == question.ExamQuestionID).Select(c => c.QuestionID).ToList();
                EAD.Question tempQuestion;

                for (int j = 0; j < QuestionIDs.Count; j++)
                {
                    tempQuestion = dbQuestion.Where(s => s.PKID == QuestionIDs.ElementAt(j)).First();
                    Question newQuest = new Question();
                    newQuest.PKID        = tempQuestion.PKID;
                    newQuest.Description = tempQuestion.Description;
                    newQuest.Answers     = GetAnswersQuestion(newQuest.PKID);
                    question.quest.Add(newQuest);
                }
                result.Add(question);
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Returnsa list of all the SUbjects with their categories
        /// and categories has a list of subtopics.
        /// </summary>
        /// <returns></returns>
        public List <Subject> GetAllSubject()
        {
            AutoMapperConfiguration.Configure();
            List <Subject> result = new List <Subject>();

            List <EAD.Subject> subjects = db.Subject.ToList();

            for (int i = 0; i < subjects.ToList().Count; i++)
            {
                Subject newSubject = Mapper.Map <Subject>(subjects.ElementAt(i));


                List <EAD.Subject_Categories> categories = db.Subject_Categories.Where(c => c.Subject_ID == newSubject.Subject_ID).ToList();
                if (categories.Count < 1)
                {
                    result.Add(newSubject);
                }
                else
                {
                    for (int b = 0; b < categories.Count; b++)
                    {
                        int tempID = categories.ElementAt(b).Categories_ID;
                        List <EAD.Categories> categoriesL = db.Categories.Where(c => c.Categories_ID == tempID).ToList();
                        Category Tempcategory             = new Category();
                        Tempcategory.Categories_ID   = categoriesL.ElementAt(0).Categories_ID;
                        Tempcategory.Categories_Name = categoriesL.ElementAt(0).Categories_Name;

                        var SubtopicIDs = from TempID in db.Categories_Subtopic
                                          where TempID.Categories_ID == Tempcategory.Categories_ID
                                          select TempID.Subtopic_ID;
                        if (SubtopicIDs.Count() < 1)
                        {
                            newSubject.listCat.Add(Tempcategory);
                            result.Add(newSubject);
                        }
                        else
                        {
                            for (int c = 0; c < SubtopicIDs.ToList().Count; c++)
                            {
                                SubTopic            newSub    = new SubTopic();
                                int                 id        = SubtopicIDs.ToList().ElementAt(c);
                                List <EAD.Subtopic> Subtopics = db.Subtopic.Where(s => s.Subtopic_ID == id).ToList();
                                newSub = Mapper.Map <SubTopic>(Subtopics.ElementAt(0));

                                Tempcategory.subtopics.Add(newSub);
                            }
                            newSubject.listCat.Add(Tempcategory);
                            result.Add(newSubject);
                        }
                    }
                }
            }
            return(result.Distinct().ToList());
        }
コード例 #4
0
        public Category getCategory(int item)
        {
            var      dbSubtopics = db.Subtopic.ToList();
            Category newCategory = new Category();

            newCategory = Mapper.Map <Category>(dbCategories.Where(x => x.Categories_ID == item).First());
            var subtopicIDS = dbCategories.Where(x => x.Categories_ID == item).First().Categories_Subtopic.Select(x => x.Subtopic_ID).ToList();

            foreach (var subID in subtopicIDS)
            {
                SubTopic newSubtopic = SubTopicAction.getSubtopic(subID);
                newCategory.subtopics.Add(newSubtopic);
            }
            return(newCategory);
        }
コード例 #5
0
        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            AutoMapperConfiguration.Configure();
            SubTopic test2 = new SubTopic();

            try
            {
                if (composite == null)
                {
                    throw new ArgumentNullException("composite");
                }
                if (composite.BoolValue)
                {
                    composite.StringValue += "Suffix";
                }
            }
            catch (Exception ex)
            {
                //to do
            }
            return(composite);
        }
コード例 #6
0
        /// <summary>
        /// Returns a full exam Template
        /// which inclueds the Exam Template itself
        /// as well as all the exam Questions attached to that exam.
        /// The exam Questions will have multiple questions attached to them.
        /// Exam Questions Can have multiple categoreis attached to them.
        /// Each question has all the answers attached to it.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ExamTemplate getExamTemplate(String id)
        {
            AutoMapperConfiguration.Configure();

            List <EAD.ExamTemplate> ExamTemplate = db.ExamTemplate.Where(s => s.ExamTemplateID == id).ToList();
            ExamTemplate            exam         = ExamAction.getExam(id);


            List <EAD.ExamTemplateQuestions> ExamQuestions = db.ExamTemplateQuestions.Where(s => s.ExamTemplateID == exam.ExamTemplateID).ToList();

            if (ExamQuestions.Count < 1)
            {
                return(exam);
            }
            else
            {
                var dbExamQuestion     = db.ExamQuestion.ToList();
                var dbExamQuestionList = db.ExamQuestionList.ToList();
                var dbQuestionAnswers  = db.QuestionAnswers.ToList();
                var dbquestion         = db.Question.ToList();
                var dbanswer           = db.Answer.ToList();
                var dbCategories       = db.Categories.ToList();
                var dbSubtopics        = db.Subtopic.ToList();

                for (int i = 0; i < ExamQuestions.Count(); i++)
                {
                    List <EAD.ExamQuestion> ExamQuestion = dbExamQuestion.Where(s => s.ExamQuestionID == ExamQuestions.ElementAt(i).ExamQuestionID).ToList();


                    ExamQuestion ExamQ = new ExamQuestion();

                    ExamQ.ExamQuestionID                = ExamQuestion.ElementAt(0).ExamQuestionID;
                    ExamQ.ExamQuestionName              = ExamQuestion.ElementAt(0).ExamQuestionName;
                    ExamQ.PKID                          = ExamQuestion.ElementAt(0).PKID;
                    ExamQ.QuestionType.PKID             = ExamQuestion.ElementAt(0).QuestionType.PKID;
                    ExamQ.QuestionType.QuestionTypeName = ExamQuestion.ElementAt(0).QuestionType.QuestionTypeName;
                    var             categoryIDs     = ExamQuestion.ElementAt(0).ExamQuestion_Categories.Select(x => x.Categories_ID).ToList();
                    List <Category> ExamQCategories = new List <Category>();

                    foreach (var item in categoryIDs)
                    {
                        Category newCategory = new Category();
                        newCategory = Mapper.Map <Category>(dbCategories.Where(x => x.Categories_ID == item).First());
                        var subtopicIDS = dbCategories.Where(x => x.Categories_ID == item).First().Categories_Subtopic.Select(x => x.Subtopic_ID).ToList();
                        foreach (var subID in subtopicIDS)
                        {
                            SubTopic newSubtopic = new SubTopic();
                            newSubtopic = Mapper.Map <SubTopic>(dbSubtopics.Where(x => x.Subtopic_ID == subID).First());
                            newCategory.subtopics.Add(newSubtopic);
                        }
                        ExamQCategories.Add(newCategory);
                    }
                    ExamQ.ExamQuestion_Categories = ExamQCategories;
                    var ExamQuestionList = dbExamQuestionList.Where(s => s.ExamQuestionID == ExamQ.ExamQuestionID).ToList();
                    for (int j = 0; j < ExamQuestionList.Count; j++)
                    {
                        int tempID = ExamQuestionList.ElementAt(j).QuestionID;

                        List <EAD.Question> Question = dbquestion.Where(s => s.PKID == tempID).ToList();
                        Question            quest    = new Question();
                        quest.PKID        = Question.ElementAt(0).PKID;
                        quest.Description = Question.ElementAt(0).Description;
                        List <EAD.QuestionAnswers> AnswersID = dbQuestionAnswers.Where(s => s.QuestionID == quest.PKID).ToList();
                        for (int k = 0; k < AnswersID.Count; k++)
                        {
                            int answer    = AnswersID.ElementAt(k).AnswerID;
                            var TheAnswer = from tempAnswer in dbanswer
                                            where tempAnswer.PKID == answer
                                            select tempAnswer;
                            Answers ans = new Answers();
                            ans.PKID              = TheAnswer.ToArray()[0].PKID;
                            ans.Answer1           = TheAnswer.FirstOrDefault().Answer1;
                            ans.correct.isCorrect = AnswersID.ElementAt(k).IsCorrect;

                            quest.Answers.Add(ans);
                        }
                        ExamQ.quest.Add(quest);
                        exam.ExamQuestions.Add(ExamQ);
                    }
                }
                return(exam);
            }
        }