Beispiel #1
0
        public IEnumerable <QuestionDto> GetQuestionsByQuestionCategoryIdAndExamPaperId(int categoryId, int examPaperId)
        {
            DbContext.Configuration.ProxyCreationEnabled = false;

            List <int> temQuestionId = new List <int>();
            List <ExamPaperQuesion> examPaperQuesions = new List <ExamPaperQuesion>();

            examPaperQuesions = examPaperQuestionRepository.GetExamPaperQuesionsByExamPaperId(examPaperId).ToList();
            foreach (var item in examPaperQuesions)
            {
                temQuestionId.Add(item.QuestionID);
            }

            var questions = DbContext.Questions.Where(e => e.CategoryID == categoryId).ToList();
            List <QuestionDto> questionsDto = new List <QuestionDto>();

            foreach (var item in questions)
            {
                int i = 0;
                foreach (var id in temQuestionId)
                {
                    if (item.QuestionID == id)
                    {
                        i++;
                        break;
                    }
                }
                if (i == 0)
                {
                    var QuestionDto = new QuestionDto();
                    QuestionDto.IsActive     = item.IsActive;
                    QuestionDto.Content      = item.Content;
                    QuestionDto.Image        = item.Image;
                    QuestionDto.CreatedBy    = item.CreatedBy;
                    QuestionDto.CreatedDate  = item.CreatedDate;
                    QuestionDto.ModifiedBy   = item.ModifiedBy;
                    QuestionDto.ModifiedDate = item.ModifiedDate;
                    QuestionDto.CategoryID   = item.CategoryID;
                    QuestionDto.CategoryName = DbContext.QuestionCategories.SingleOrDefault(q => q.CategoryID == item.CategoryID).Name;
                    QuestionDto.QuestionID   = item.QuestionID;
                    if (item.Level == 1)
                    {
                        QuestionDto.LevelName = "Easy";
                    }
                    else if (item.Level == 2)
                    {
                        QuestionDto.LevelName = "Normal";
                    }
                    else
                    {
                        QuestionDto.LevelName = "Hard";
                    }
                    questionsDto.Add(QuestionDto);
                }
            }
            return(questionsDto);
        }
Beispiel #2
0
 public IEnumerable <ExamPaperQuesion> GetExamPaperQuestionsByExamPaperId(int examPaperId)
 {
     return(examPaperQuestionRepository.GetExamPaperQuesionsByExamPaperId(examPaperId));
 }