コード例 #1
0
        public ExamViewModal GetExamData(int examid = 0)
        {
            ExamViewModal exammodel = new ExamViewModal();

            exammodel = ExamRepository.GetExamDetails(examid);

            return(exammodel);
        }
コード例 #2
0
        public static ExamViewModal GetExamDetails(int examid)
        {
            ExamViewModal examviewmodal = new ExamViewModal();

            examviewmodal.QuestionSheet           = new List <QuestionViewModel>();
            examviewmodal.ExamKnowledgeViewModals = new List <ExamKnowledgeViewModal>();
            examviewmodal.ToppersViewModels       = new List <ToppersViewModel>();
            using (QuizContext cntxt = new QuizContext())
            {
                ExamTableMain exammain = cntxt.ExamTableMains.Find(examid);

                if (exammain != null)
                {
                    examviewmodal.MarkPerQstn         = exammain.MarkPerQstn;
                    examviewmodal.NegativemarkPerQstn = exammain.NegativemarkPerQstn;
                    examviewmodal.ExamTableMainId     = exammain.ExamTableMainId;
                    examviewmodal.ExamName            = exammain.ExamName;
                    examviewmodal.TotalQuestion       = exammain.TotalQuestion;
                    examviewmodal.ExamMinutes         = exammain.ExamMinutes;
                    examviewmodal.UsedMinutes         = 0;
                    examviewmodal.Cuttoff             = exammain.Cuttoff;
                    if (exammain.ExamTableKnowledgeAreas.Count > 0)
                    {
                        var qpercentagecount = exammain.ExamTableKnowledgeAreas.Sum(u => u.Percentage);
                        if (int.Parse(qpercentagecount.ToString()) == 100)
                        {
                            foreach (var element in exammain.ExamTableKnowledgeAreas)
                            {
                                int xpectedqstn = ((element.Percentage * examviewmodal.TotalQuestion) / 100);
                                var tempQuestionViewModellist = GetNumberofQuestionofKnowledgeArea(xpectedqstn, examid, element.KnowledgeAreaID, exammain.LanguageId);

                                foreach (var tempelement in tempQuestionViewModellist)
                                {
                                    examviewmodal.QuestionSheet.Add(tempelement);
                                }

                                ExamKnowledgeViewModal examKnowledgeViewModal = new ExamKnowledgeViewModal();
                                examKnowledgeViewModal.KnowledgeAreaID   = element.KnowledgeAreaID;
                                examKnowledgeViewModal.KnowledgeAreaName = element.KnowledgeArea.KnowledgeAreaName;
                                examKnowledgeViewModal.TotalQstn         = tempQuestionViewModellist.Count;
                                examviewmodal.ExamKnowledgeViewModals.Add(examKnowledgeViewModal);
                            }
                        }
                    }
                }
            }
            try
            {
                examviewmodal.QuestionSheet.ShuffleMe();
                examviewmodal.ToppersViewModels = GetTopper(examid);
            }
            catch (Exception)
            {
                throw;
            }
            return(examviewmodal);
        }
コード例 #3
0
 public ExamViewModal Post(ExamViewModal examviewmodal)
 {
     return(ExamRepository.CalculateResultData(examviewmodal));
 }
コード例 #4
0
        public static ExamViewModal CalculateResultData(ExamViewModal examViewModal)
        {
            int correctAnswercount = 0;
            int WrongAnswerCount   = 0;
            int NoAnswerCount      = 0;

            foreach (QuestionViewModel qvmodel in examViewModal.QuestionSheet)
            {
                var question = QuizAPI.Repository.QuestionRepository.GetQuestion(qvmodel.QuestionId);

                qvmodel.CorrectAnswer = question.CorrectAnswerIndex;

                int knowledgeareaid = question.KnowledgeAreaId;



                if (qvmodel.UserAnswer.Trim() == "")
                {
                    qvmodel.isCorrect = "S";
                    NoAnswerCount++;
                }
                else
                {
                    if (qvmodel.UserAnswer.Trim() == qvmodel.CorrectAnswer.Trim())
                    {
                        qvmodel.isCorrect = "Y";
                        correctAnswercount++;
                    }
                    else
                    {
                        qvmodel.isCorrect = "N";
                        WrongAnswerCount++;
                    }
                }


                var asd = from cnt in examViewModal.ExamKnowledgeViewModals
                          where cnt.KnowledgeAreaID == knowledgeareaid
                          select cnt;
                foreach (var element in asd)
                {
                    if (qvmodel.isCorrect == "Y")
                    {
                        element.CorrectAnswerCount = element.CorrectAnswerCount + 1;
                    }
                    else if (qvmodel.isCorrect == "S")
                    {
                        element.NoAnswerCount = element.NoAnswerCount + 1;
                    }
                    else if (qvmodel.isCorrect == "N")
                    {
                        element.WrongAnswersCount = element.WrongAnswersCount + 1;
                    }
                }
            }



            examViewModal.correctAnswercount = correctAnswercount;
            examViewModal.WrongAnswerCount   = WrongAnswerCount;
            examViewModal.NoAnswerCount      = NoAnswerCount;

            examViewModal.TotalMark    = correctAnswercount * examViewModal.MarkPerQstn;
            examViewModal.Negativemark = WrongAnswerCount * examViewModal.NegativemarkPerQstn;

            examViewModal.FinalMark = examViewModal.TotalMark - examViewModal.Negativemark;



            using (QuizContext cntxt = new QuizContext())
            {
                CandidateResult canreslt = new CandidateResult();
                canreslt.CandidateId        = examViewModal.Candidateviewmodal.CandidateId;
                canreslt.ExamTableMainId    = examViewModal.ExamTableMainId;
                canreslt.correctAnswercount = examViewModal.correctAnswercount;
                canreslt.WrongAnswerCount   = examViewModal.WrongAnswerCount;
                canreslt.NoAnswerCount      = examViewModal.NoAnswerCount;
                canreslt.UsedMinutes        = examViewModal.UsedMinutes;
                canreslt.TotalQuestion      = examViewModal.TotalQuestion;
                canreslt.TotalMark          = examViewModal.TotalMark;
                canreslt.Negativemark       = examViewModal.Negativemark;
                canreslt.FinalMark          = examViewModal.FinalMark;
                canreslt.ExamDate           = DateTime.Now;
                cntxt.CandidateResults.Add(canreslt);
                cntxt.SaveChanges();

                foreach (ExamKnowledgeViewModal knwmdl in examViewModal.ExamKnowledgeViewModals)
                {
                    CandidateResultDetail canresltdet = new CandidateResultDetail();
                    canresltdet.CandidateResultId  = canreslt.CandidateResultId;
                    canresltdet.KnowledgeAreaID    = knwmdl.KnowledgeAreaID;
                    canresltdet.TotalQstn          = knwmdl.TotalQstn;
                    canresltdet.WrongAnswersCount  = knwmdl.WrongAnswersCount;
                    canresltdet.NoAnswerCount      = knwmdl.NoAnswerCount;
                    canresltdet.CorrectAnswerCount = knwmdl.CorrectAnswerCount;
                    cntxt.CandidateResultDetails.Add(canresltdet);
                    cntxt.SaveChanges();
                }
            }



            return(examViewModal);
        }