コード例 #1
0
        public ExamSheetRespone GetSheet(string pid, string subjectCode, string clientid)
        {
            var regis = repoOnSite.GetTestRegisInfo(pid, subjectCode);

            if (regis.MaxCount <= regis.LatestCount)
            {
                return(null);
            }

            ExamSheet sheet = new ExamSheet();

            //Get available exam sheet if haven't availble return null
            if (repoOnSite.GetSheetBySubjectCodeForMap(subjectCode, regis.ExamLanguage) == null)
            {
                return(new ExamSheetRespone {
                    Message = new ViewModels.MessageRespone {
                        Code = "1", Message = string.Format(getsheet1, subjectCode, regis.ExamLanguage).ToString()
                    }
                });
            }

            var oldsheet = repoOnSite.GetSheetByPIDAndSubjectCode(pid, subjectCode, regis.ExamLanguage);

            if (oldsheet.ClientId == null)
            {
                sheet = repoOnSite.GetSheetBySubjectCodeForMap(subjectCode, regis.ExamLanguage);
                sheet.RandomQuestions = new List <Question>(GetQuestion(sheet.RandomQuestions));
            }
            else
            {
                if (oldsheet.LatestStatus == "FAIL")
                {
                    sheet = repoOnSite.GetSheetBySubjectCodeForMap(subjectCode, regis.ExamLanguage);
                }
                else if (oldsheet.LatestStatus == "RESUME")
                {
                    sheet = oldsheet;
                }
                else if (oldsheet.LatestStatus != "RESUME")
                {
                    return(new ExamSheetRespone {
                        Message = new ViewModels.MessageRespone {
                            Code = "2", Message = getsheet2
                        }
                    });
                }
                else if (oldsheet.LatestStatus == "PASS")
                {
                    return(new ExamSheetRespone {
                        Message = new ViewModels.MessageRespone {
                            Code = "3", Message = getsheet3
                        }
                    });
                }
            }

            if (sheet.LatestStatus != "RESUME")
            {
                int testCount = regis.LatestCount + 1;

                sheet.TestCount   = testCount;
                regis.LatestCount = testCount;
            }

            sheet.TestRegisID = regis._id;
            sheet.PID         = regis.PID;

            var newStatus = new StatusExtension
            {
                _id            = Guid.NewGuid().ToString(),
                ClientId       = clientid,
                CreateDateTime = DateTime.Now,
                Status         = "Ready",
            };

            if (sheet.StatusExtensions == null)
            {
                sheet.StatusExtensions = new List <StatusExtension>();
                sheet.StatusExtensions.Add(newStatus);
            }
            else
            {
                sheet.StatusExtensions.Add(newStatus);
            }

            sheet.ClientId     = clientid;
            sheet.LatestStatus = "Ready";

            repoOnSite.UpdateSheet(sheet);
            repoOnSite.UpdateTestRegis(regis);

            var activeInfo = repoOnSite.GetLastActive();

            var result = new ExamSheetRespone
            {
                _id                = sheet._id,
                Title              = regis.Title,
                FirstName          = regis.FirstName,
                LastName           = regis.LastName,
                PID                = regis.PID,
                ExamNumber         = regis.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       = 0,
                InCorrectScore     = 0,
                ExamDuration       = sheet.Subject.ExamDuration,
                ReviewDuration     = sheet.ReviewDuration,
                ActiveThruDateTime = activeInfo.ActiveThruDateTime,
                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 = null,
                    }).ToList(),
                }).ToList(),
                Message = new MessageRespone {
                    Code = "0", Message = getsheet0
                }
            };

            return(result);
        }