Ejemplo n.º 1
0
        public void UpsertInActiveSubject(InActive.InactiveSubject InactiveSubject)
        {
            var coltn = helper.GetCollection <InActive.InactiveSubject>(InactiveSubject_InactiveSubject);
            var opt   = new UpdateOptions()
            {
                IsUpsert = true,
            };

            coltn.ReplaceOne(it => it._id == InactiveSubject._id, InactiveSubject, opt);
        }
Ejemplo n.º 2
0
        public void InsertInActiveSubject(InActive.InactiveSubject InactiveSubject)
        {
            var coltn = helper.GetCollection <InActive.InactiveSubject>(InactiveSubject_InactiveSubject);

            //var opt = new UpdateOptions()
            //{
            //    IsUpsert = true,
            //};
            //coltn.ReplaceOne(it => it._id == InactiveSubject._id, InactiveSubject, opt);
            coltn.InsertOne(InactiveSubject);
        }
Ejemplo n.º 3
0
 public void UpsertInactiveSubject(InActive.InactiveSubject inactiveSubject)
 {
     if (inactiveSubject != null)
     {
         var coltn = helper.GetCollection <InActive.InactiveSubject>(InactiveSubject_InactiveSubject);
         var opt   = new UpdateOptions()
         {
             IsUpsert = true,
         };
         coltn.ReplaceOne(it => it._id == inactiveSubject._id, inactiveSubject, opt);
     }
     else
     {
         throw new ArgumentNullException("null input from inactiveSubject ");
     }
 }
Ejemplo n.º 4
0
        public IActionResult VerifyMarkdown(IEnumerable <IFormFile> files, string Language)
        {
            var    mdFi = files.FirstOrDefault(f => System.IO.Path.GetExtension(ContentDispositionHeaderValue.Parse(f.ContentDisposition).FileName.Trim('"')) == ".md");
            string md   = string.Empty;

            if (mdFi != null)
            {
                using (var fi = new System.IO.StreamReader(mdFi.OpenReadStream()))
                {
                    md = fi.ReadToEnd();
                }
            }

            List <string> fileList  = new List <string>();
            var           subjectId = string.Empty;

            foreach (var f in files)
            {
                using (var fi = f.OpenReadStream())
                {
                    if (ZipFile.IsZipFile(fi, true))
                    {
                        fi.Seek(0, System.IO.SeekOrigin.Begin);
                        var assets = TheS.ExamBank.Parsers.AssetFileUtil.ReadZipEntries(fi).ToArray();
                        var parser = new TheS.ExamBank.Parsers.MarkdownParser();
                        if (parser.CheckAssets(md, assets))
                        {
                            fileList = assets.ToList();
                            assets   = parser.GetAssetLinks(md).ToArray();

                            fi.Seek(0, System.IO.SeekOrigin.Begin);
                            var assetFiles = TheS.ExamBank.Parsers.AssetFileUtil.GetAssets(fi, assets);
                            try
                            {
                                var questions = parser.ParseQuestionsFromString(md);
                                var header    = parser.ParseHeaderFromString(md);
                                subjectId = string.Concat(header.SubjectCode + "L" + header.Level, Language);

                                var qcode  = (header.Code ?? string.Empty).Trim();
                                var qid    = string.Concat(qcode, Language);
                                var qsuite = new TheS.ExamBank.DataFormats.QuestionSuite()
                                {
                                    _id         = qid,
                                    Code        = qcode,
                                    Title       = header.Title,
                                    SubjectName = header.SubjectName,
                                    Description = header.Description,
                                    SubjectId   = subjectId,
                                    SubjectCode = header.SubjectCode,
                                    Level       = header.Level,
                                    LayoutCode  = header.LayoutCode,

                                    Questions = questions,
                                };

                                var inActiveSubject = repoQ.GetInActiveSubject(subjectId);
                                var suite           = repoQ.GetQuestionSuite(qid);

                                //no suite and no subject  : create new suite and subject
                                if (suite == null && inActiveSubject == null)
                                {
                                    if (inActiveSubject == null)
                                    {
                                        var newSubject = new InActive.InactiveSubject
                                        {
                                            _id                  = subjectId,
                                            SubjectCode          = qsuite.SubjectCode,
                                            SubjectName          = qsuite.SubjectName,
                                            CreateDateTime       = DateTime.Now,
                                            IsEReadiness         = false, //Hack
                                            ContentLanguage      = Language,
                                            SiteId               = HomeController._centerdata.SiteId,
                                            QuestionCount        = questions.Count(),
                                            ExamSuiteCount       = 1,
                                            ExamSuiteAcceptCount = 0,
                                            ExamSuiteRejectCount = 0,
                                            ExamSuiteGroups      = new List <InActive.ExamSuiteGroup>()
                                            {
                                                new InActive.ExamSuiteGroup {
                                                    _id = "ก",
                                                    ExamSuiteGroupName = "ก", // HACK
                                                    IsUsed             = true,
                                                    PassScore          = null,
                                                    ExamDuration       = null,
                                                    ExamSuiteGroupMaps = new List <InActive.ExamSuiteGroupMap>
                                                    {
                                                        new InActive.ExamSuiteGroupMap
                                                        {
                                                            _id         = Guid.NewGuid().ToString(),
                                                            ExamSuiteId = qid,
                                                            RandomCount = 0,
                                                        }
                                                    },
                                                }
                                            },
                                        };
                                        repoQ.InsertInActiveSubject(newSubject);
                                    }
                                }
                                //has old suite and already has subject  : upsert suite   add groupmap to new suite
                                //ใช้ group map เดิม
                                else if (inActiveSubject != null && suite != null)
                                {
                                    //suite upsert ปกติ  subject ไม่เปลี่ยนอะไร
                                }
                                //new suite and already has subject : add groupmap to new suite
                                //เพิ่ม group map ใหม่
                                else if (inActiveSubject != null && suite == null)
                                {
                                    foreach (var item in inActiveSubject.ExamSuiteGroups)
                                    {
                                        item.ExamSuiteGroupMaps.Add(new InActive.ExamSuiteGroupMap
                                        {
                                            _id         = repoExamForApprove.GetNewGuid("").ToString(),
                                            ExamSuiteId = qid,
                                            RandomCount = 0,
                                        });
                                    }

                                    repoQ.UpsertInActiveSubject(inActiveSubject);
                                }

                                if (inActiveSubject != null)
                                {
                                    //update SubjectName and ContentLanguage
                                    repoQ.UpdateSubjectNameAndContentLanguage(inActiveSubject._id, qsuite.SubjectName, Language);
                                    //UpdateQuestionCount UpdateExamSuiteCount
                                    var examSuites    = repoQ.GetAllQuestionSuiteBySubjectId(subjectId);
                                    var questionCount = examSuites.Sum(es => es.Questions.Count());
                                    repoQ.UpdateQuestionCount(subjectId,
                                                              questionCount + questions.Count(),
                                                              examSuites.Count() + 1);
                                }

                                repoQ.Upsert(qsuite);
                                repoQ.UploadAssets(assetFiles, qid, this.iCloudStorage);
                            }
                            finally
                            {
                                TheS.ExamBank.Parsers.AssetFileUtil.CleanUpAssets(assetFiles, iFile);
                            }
                        }
                    }
                }
            }

            ViewData["files"] = fileList;

            return(Redirect("~/#!/inactivesubjectview/" + subjectId));
        }
        private Activated.Subject ConvertToActivatedSubject(InActive.InactiveSubject inActiceSubject, IEnumerable <QuestionSuiteVM> inActiveSuite, DateTime now, out List <Activated.Question> question)
        {
            if (inActiceSubject == null || inActiveSuite.Count() == 0)
            {
                question = new List <Activated.Question>();
                return(null);
            }

            var newSubId = repoForApprove.GetNewSubId("").ToString();

            Activated.Subject newSubject = new Activated.Subject()
            {
                _id             = newSubId,
                SubjectCode     = inActiceSubject.SubjectCode,
                SubjectName     = inActiceSubject.SubjectName,
                CreateDateTime  = now,
                ContentLanguage = inActiceSubject.ContentLanguage,
                Version         = "", // รอถามโต
                ExamSuites      = new List <Activated.ExamSuite>(),
                //ExamSuites = inActiveSuite.Select(x => new Activated.ExamSuite
                //{
                //    _id = x.Code,
                //    TitleCode = x.Code,
                //    TitleName = x.Title,
                //    CreateDateTime = now,
                //    QuestionIds = x.Questions.Select(y => y._id).ToList(),
                //}).ToList(),
                ExamSuiteGroups = inActiceSubject.ExamSuiteGroups.Select(esg => new Activated.ExamSuiteGroup
                {
                    _id = esg.ExamSuiteGroupName,
                    ExamSuiteGroupName = esg.ExamSuiteGroupName,
                    IsUsed             = esg.IsUsed,
                    PassScore          = esg.PassScore,
                    ExamDuration       = esg.ExamDuration,
                    ExamSuiteGroupMaps = esg.ExamSuiteGroupMaps.Select(esgm => new Activated.ExamSuiteGroupMap
                    {
                        _id         = esgm._id,
                        ExamSuiteId = esgm.ExamSuiteId,
                        RandomCount = esgm.RandomCount,
                    }).ToList(),
                }).ToList(),
                //  TODO: Add VoiceLanguages ??
                VoiceLanguages = new List <Activated.VoiceLanguage> {
                    new Activated.VoiceLanguage {
                        Language     = inActiceSubject.ContentLanguage,
                        LanguageCode = inActiceSubject.ContentLanguage,
                        IsUsed       = true
                    }
                },
            };

            List <Activated.Question> newQuestion = new List <Activated.Question>();

            foreach (var item in inActiveSuite)
            {
                var qInSuite = ConvertToActivedQuestion(item, now);

                newQuestion.AddRange(qInSuite);

                newSubject.ExamSuites.Add(new Activated.ExamSuite
                {
                    _id            = item._id,
                    TitleCode      = item.Code,
                    TitleName      = item.Title,
                    CreateDateTime = now,
                    QuestionIds    = qInSuite.Select(x => x._id).ToList(),
                });
            }

            question = newQuestion;

            return(newSubject);
        }