예제 #1
0
 public static OATSDBEntities Instance()
 {
     //if (_oatsEntities == null)
     //{
     //    _oatsEntities = new OATSDBEntities();
     //}
     _oatsEntities = new OATSDBEntities();
     return _oatsEntities;
 }
 public static AuthenticationSessionModel Instance(OATSDBEntities iDb)
 {
     if (_authenticationSessionModel == null)
     {
         _authenticationSessionModel = new AuthenticationSessionModel();
         _authenticationSessionModel.db = iDb;
     }
     return _authenticationSessionModel;
 }
예제 #3
0
        private void InitResponseTest(Test test, List<int> checkIds)
        {
            db = SingletonDb.Instance();
            var inTestsValid = test.UserInTests.FilterInTestsOnAttempSetting();
            IsHaveData = inTestsValid.Count > 0;
            TestTitle = test.TestTitle;
            TotalScoreOfTest = test.Questions.TotalRealScore();

            CheckedUserIds = checkIds;
            if (checkIds.Count == 1)
            {
                var id = checkIds.FirstOrDefault();
                var inTest = inTestsValid.FirstOrDefault(i => i.UserID == id);
                if (inTest != null)
                {
                    testTakenDate = String.Format("{0:dd MMM yyyy HH:mm tt}", inTest.TestTakenDate);
                    UserScoreResult = string.Format("{0:0.00}/{1:0.00}", inTest.Score ?? 0, TotalScoreOfTest ?? 0);
                }
            }

            var details = inTestsValid.ToList();
            ResponseUserList = new List<ResponseUserItem>();
            details.ForEach(i =>
            {
                if (i.User != null)
                {
                    var item = new ResponseUserItem();
                    item.UserLabel = !string.IsNullOrEmpty(i.User.Name) ? i.User.Name : i.User.UserMail;
                    item.UserPercent = TotalScoreOfTest != 0 && TotalScoreOfTest.HasValue?((decimal)i.Score / TotalScoreOfTest).ToPercent():"0%";
                    item.UserID = i.User.UserID;
                    ResponseUserList.Add(item);
                }
            });
            var questions = test.Questions.ToList();
            questions = questions.OrderBy(i => i.SerialOrder).ToList();
            Questions = new List<AbsResponseQuestion>();
            if (checkIds.Count > 0)
            {
                questions.ForEach(i =>
                {
                    AbsResponseQuestion item = null;
                    switch (i.QuestionType.Type)
                    {
                        case "Radio":
                            item = new ResponseQuestionRadio(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        case "Multiple":
                            item = new ResponseQuestionMultile(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        case "Essay":
                            item = new ResponseQuestionEssay(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        case "ShortAnswer":
                            item = new ResponseQuestionShort(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        case "Text":
                            item = new ResponseQuestionText(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        case "Image":
                            item = new ResponseQuestionImage(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        case "Matching":
                            item = new ResponseQuestionMatching(i, CheckedUserIds);
                            Questions.Add(item);
                            break;
                        default:
                            break;
                    }
                });
            }
        }