Пример #1
0
 public void UpsertSubject(Activated.Subject subject)
 {
     if (subject != null)
     {
         var coltn = helper.GetCollection <Activated.Subject>(ActivatedSubject_Subject);
         var opt   = new UpdateOptions()
         {
             IsUpsert = true,
         };
         coltn.ReplaceOne(it => it._id == subject._id, subject, opt);
     }
     else
     {
         throw new ArgumentNullException("null input from ActivatedSubject subject ");
     }
 }
        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);
        }