Esempio n. 1
0
        public JsonResult GetListQuestion(int accountId, int examId, int page)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //Check id exam exist in the database
                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //This is get all questions of the exam by id exam
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);
                List <AnswerUserEntity>   answerUsers        = _answerUserRepository.GetAnswerUserEntities(accountId);

                List <QuestionEntity> listQuestionEntities = new List <QuestionEntity>();
                foreach (var examQuestion in examQuestionEntity)
                {
                    // Get all informations of the question by questionId and save it in the list
                    QuestionEntity questionEntity = _questionRepository.getQuestionInformation(examQuestion.QuestionId);
                    listQuestionEntities.Add(questionEntity);
                }

                List <QuestionListResult> questionLists = new List <QuestionListResult>();
                foreach (var item in listQuestionEntities)
                {
                    QuestionListResult q = new QuestionListResult();
                    q.questionId    = item.QuestionId;
                    q.part          = item.Part;
                    q.image         = item.Image;
                    q.fileMp3       = item.FileMp3;
                    q.questionName  = item.QuestionName;
                    q.A             = item.A;
                    q.B             = item.B;
                    q.C             = item.C;
                    q.D             = item.D;
                    q.correctAnswer = item.CorrectAnswer;
                    q.team          = item.Team;
                    foreach (var answer in answerUsers)
                    {
                        if (q.questionId == answer.QuestionId)
                        {
                            q.answerUser = answer.AnswerKey;
                        }
                    }
                    questionLists.Add(q);
                }

                List <QuestionListResult> pagging = Pagging.GetQuestions(page, questionLists);

                return(Json(pagging));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Esempio n. 2
0
        public JsonResult GetAnswerKeyAndCorrectAnswer(int examId, int accountId, int anotherAccountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);

                List <QuestionEntity> listQuestionEntities = new List <QuestionEntity>();
                foreach (var examQuestion in examQuestionEntity)
                {
                    // Get all informations of the question by questionId and save it in the list
                    QuestionEntity questionEntity = _questionRepository.getQuestionInformation(examQuestion.QuestionId);
                    listQuestionEntities.Add(questionEntity);
                }

                List <AnswerUserEntity> answerUserEntities = _answerUserRepository.GetAnswerUserEntities(accountId);

                List <AnswerUserResult> answerUserResults = new List <AnswerUserResult>();

                if (anotherAccountId <= 0)
                {
                    foreach (var examQuestion in listQuestionEntities)
                    {
                        foreach (var item in answerUserEntities)
                        {
                            if (item.QuestionId == examQuestion.QuestionId)
                            {
                                AnswerUserResult answerUser = new AnswerUserResult();
                                answerUser.part          = examQuestion.Part;
                                answerUser.quetionNumber = examQuestion.QuestionNumber;
                                answerUser.answerUser    = item.AnswerKey.ToUpper();
                                answerUser.finalAnswer   = examQuestion.CorrectAnswer.ToUpper();

                                answerUserResults.Add(answerUser);
                            }
                        }
                    }
                }
                else if (anotherAccountId > 0)
                {
                    List <AnswerUserEntity> anotherAccount = _answerUserRepository.GetAnswerUserEntities(anotherAccountId);
                    AccountEntity           nameAnother    = _accountRepository.GetAccountById(anotherAccountId);
                    foreach (var examQuestion in listQuestionEntities)
                    {
                        foreach (var item in answerUserEntities)
                        {
                            foreach (var another in anotherAccount)
                            {
                                if (item.QuestionId == examQuestion.QuestionId && another.QuestionId == examQuestion.QuestionId)
                                {
                                    AnswerUserResult answerUser = new AnswerUserResult();
                                    answerUser.part          = examQuestion.Part;
                                    answerUser.nameAnother   = nameAnother.FullName;
                                    answerUser.quetionNumber = examQuestion.QuestionNumber;
                                    answerUser.answerUser    = item.AnswerKey.ToUpper();
                                    answerUser.finalAnswer   = examQuestion.CorrectAnswer.ToUpper();
                                    answerUser.answerAnother = another.AnswerKey.ToUpper();

                                    if (!item.AnswerKey.Equals(another.AnswerKey))
                                    {
                                        answerUser.status = "uncorrect";
                                    }

                                    answerUserResults.Add(answerUser);
                                }
                            }
                        }
                    }
                }

                return(Json(answerUserResults.OrderBy(a => a.quetionNumber)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }