示例#1
0
        public Result GetTestResult(string pid, string sheetid)
        {
            var sheet = repoOnSite.GetTestResultInfo(pid, sheetid);

            var regis = repoOnSite.GetTestRegisById(sheet.TestRegisID);

            var center = this.GetCenterData();

            var result = new Result
            {
                _id            = sheet._id,
                Title          = regis.Title,
                Firstname      = regis.FirstName,
                LastName       = regis.LastName,
                SubjectCode    = sheet.Subject.SubjectCode,
                SubjectName    = sheet.Subject.SubjectName,
                ExamNumber     = regis.ExamNumber,
                PID            = regis.PID,
                Status         = sheet.LatestStatus,
                TestCount      = sheet.TestCount,
                CorrectCount   = sheet.CorrectScore,
                InCorrectCount = sheet.InCorrectScore,
                ExamDateTime   = sheet.StartDateTime.HasValue ? sheet.StartDateTime.Value : new DateTime(),
                CenterNameTH   = center.NameTh,
            };

            return(result);
        }
示例#2
0
        public ResultRespone SendExam(string sheetId, string clientid)
        {
            var sheet = repoOnSite.GetSheetBySheetId(sheetId);

            if (sheet != null)
            {
                foreach (var item in sheet.RandomQuestions)
                {
                    if (item.UserAnswer != null)
                    {
                        item.UserAnswer.IsCorrect = item.Choices.Where(x => x._id == item.UserAnswer._id).FirstOrDefault().IsCorrect;
                    }
                }

                //sheet.CorrectScore = sheet.RandomQuestions.Where(x => x.UserAnswer.IsCorrect.Value).Count();
                sheet.CorrectScore = sheet.RandomQuestions.Where(x => x.UserAnswer != null && x.UserAnswer.IsCorrect.Value).Count();
                //sheet.InCorrectScore = sheet.RandomQuestions.Where(x => !x.UserAnswer.IsCorrect.Value).Count();
                sheet.InCorrectScore = sheet.RandomQuestions.Count() - sheet.CorrectScore;

                var newStatus = new StatusExtension
                {
                    _id            = Guid.NewGuid().ToString(),
                    ClientId       = clientid,
                    CreateDateTime = DateTime.Now,
                    Status         = "DONE"
                };
                sheet.StatusExtensions.Add(newStatus);
                sheet.LatestStatus = newStatus.Status;
                sheet.DoneDateTime = DateTime.Now;
                repoOnSite.UpdateSheet(sheet);

                var testregis = repoOnSite.GetTestRegisById(sheet.TestRegisID);


                ResultRespone result = new ResultRespone()
                {
                    //IsShowAnswer = repoOnSite.GetCenter().IsShowAnswer,
                    IsShowAnswer      = true,
                    ExamSheetRespones = new ExamSheetRespone()
                    {
                        _id                = sheet._id,
                        Title              = testregis.Title,
                        FirstName          = testregis.FirstName,
                        LastName           = testregis.LastName,
                        PID                = testregis.PID,
                        ExamNumber         = testregis.ExamNumber,
                        SubjectCode        = sheet.Subject.SubjectCode,
                        SubjectName        = sheet.Subject.SubjectName,
                        IsEReadiness       = sheet.Subject.IsEReadiness,
                        ContentLanguage    = sheet.Subject.ContentLanguage,
                        TestCount          = sheet.TestCount,
                        LastedStatus       = sheet.LatestStatus,
                        PassScore          = sheet.Subject.PassScore,
                        CorrectScore       = sheet.CorrectScore,
                        InCorrectScore     = sheet.InCorrectScore,
                        ExamDuration       = sheet.Subject.ExamDuration,
                        ReviewDuration     = sheet.ReviewDuration,
                        ActiveThruDateTime = sheet.ActiveThruDateTime.Value,
                        ClientId           = clientid,
                        Questions          = sheet.RandomQuestions.Select(q => new Question
                        {
                            _id                 = q._id,
                            QuestionNumber      = q.QuestionNumber,
                            IsAllowRandomChoice = q.IsAllowRandomChoice,
                            Detail              = q.Detail,
                            GroupId             = q.GroupId,
                            //UserAnswer = q.UserAnswer == null ? new Choice() :
                            //new Choice
                            //{
                            //    _id = q.UserAnswer._id,
                            //    Detail = q.UserAnswer.Detail,
                            //    IsCorrect = q.UserAnswer.IsCorrect.Value,
                            //},
                            UserAnswer = q.UserAnswer == null ? null :
                                         new Choice
                            {
                                _id       = q.UserAnswer._id,
                                Detail    = q.UserAnswer.Detail,
                                IsCorrect = q.UserAnswer.IsCorrect.Value,
                            },
                            Choices = q.Choices.Select(c => new Choice
                            {
                                _id       = c._id,
                                Detail    = c.Detail,
                                IsCorrect = c.IsCorrect,
                            }).ToList(),
                        }).ToList(),
                    },
                };

                return(result);
            }
            else
            {
                return(null);
            }
        }