示例#1
0
        public ExamMainQuestionViewModel GetExamQuestions(string userId, string timeLookUp)
        {
            try
            {
                //Get sql time object
                var timeObjectSql = _storedProcedure.GetTimeObject(timeLookUp);
                //Get time Object mapping
                var examTimeObjectMapping = Mapper.Map <ExamScheduleTime, TimeViewModel>(timeObjectSql);

                //Get Exam topic sql
                var examTopicsQL = _storedProcedure.GetExamTopics(userId);
                //Get Exam Topic mapping
                var examTopicMapping = Mapper.Map <List <ExamTopic>, List <TopicViewModel> >(examTopicsQL);

                //initialize the view model to carry topic and subsquent question lists
                var examExamQuestionModel = new List <ExamTopicViewModel>();
                //Iterate over topics to get all the questions under it.
                foreach (var topic in examTopicMapping)
                {
                    //Get sql exam questions
                    var examQuestionSql = _storedProcedure.GetExamQuestions(topic.ExamTopicId);
                    if (examQuestionSql.Count() > 0)
                    {
                        ShuffleList.Shuffle(examQuestionSql);
                        try
                        {
                            var examQuestionModel = Mapper.Map <List <ExamQuestion>, List <ExamQuestionsViewModel> >(examQuestionSql);
                            var examTopicModels   = new ExamTopicViewModel()
                            {
                                TopicViewModel          = topic,
                                ExamQuestionsViewModels = examQuestionModel,
                            };
                            examExamQuestionModel.Add(examTopicModels);
                        }
                        catch (Exception ex) { }
                    }
                }
                //Return the View models carrying all the questions.
                var examTimeInstruction = new ExamMainQuestionViewModel()
                {
                    ExamTopicViewModels = examExamQuestionModel,
                    TimeViewModel       = examTimeObjectMapping
                };
                return(examTimeInstruction);
            }
            catch (Exception ex)
            {
                string errorMessage = "GetExamQuestions(): " + ex.Message;
                _unitOfWork.AuditTrail(errorMessage, userId);
                return(new ExamMainQuestionViewModel());
            }
        }