public Consideration ConsiderQuestion(string TitleCode, int QuestionNumber, [FromBody] Consideration consideration)
        {
            var _consideration = new InActive.Consideration()
            {
                _id            = repoForApprove.GetNewGuid("").ToString(),
                CreateDateTime = DateTime.Now,
                RejectComment  = consideration?.RejectComment,
                IsAccept       = consideration?.IsAccept ?? false,
                UserName       = consideration?.UserName, //TODO : userName ??
                ExamSuiteId    = consideration.ExamSuiteId,
                QuestionNumber = QuestionNumber,
            };

            var preConsiderationExamSuite = repoQ.GetQuestionSuite(consideration.ExamSuiteId);
            var preStatus = repoForApprove.GetConsiderationStatus(preConsiderationExamSuite);

            repoForApprove.CreateConsideration(_consideration);
            var postConsiderationExamSuite = repoQ.GetQuestionSuite(consideration.ExamSuiteId);
            var postStatus = repoForApprove.GetConsiderationStatus(postConsiderationExamSuite);

            var examSuite = repoQ.GetQuestionSuite(consideration.ExamSuiteId);
            var subject = repoQ.GetInActiveSubject(examSuite.SubjectId);
            int ExamSuiteAcceptCount = subject.ExamSuiteAcceptCount, ExamSuiteRejectCount = subject.ExamSuiteRejectCount;

            if (preStatus == "Accepted" && postStatus == "Rejected")
            {
                ExamSuiteAcceptCount--;
                ExamSuiteRejectCount++;
            }
            else if (preStatus == "Rejected" && postStatus == "Accepted")
            {
                ExamSuiteAcceptCount++;
                ExamSuiteRejectCount--;
            }
            else if (preStatus == "Wait" && postStatus == "Accepted")
            {
                ExamSuiteAcceptCount++;
            }
            else if (preStatus == "Wait" && postStatus == "Rejected")
            {
                ExamSuiteRejectCount++;
            }
            repoQ.UpdateQuestionCountComment(examSuite.SubjectId, ExamSuiteAcceptCount, ExamSuiteRejectCount);

            consideration.id             = _consideration._id;
            consideration.CreateDateTime = _consideration.CreateDateTime;
            consideration.ExamSuiteId    = consideration.ExamSuiteId;
            consideration.QuestionNumber = QuestionNumber;
            return(consideration);
        }
Esempio n. 2
0
        public string UpdateQuestionCount(string SubjectId)
        {
            var subject = repoQ.GetInActiveSubject(SubjectId);
            var examSuites = repoQ.GetAllQuestionSuiteBySubjectId(SubjectId);
            int accept = 0, reject = 0;

            foreach (var es in examSuites)
            {
                var status = repoForApprove.GetConsiderationStatus(es);
                if (status == "Accepted")
                {
                    accept++;
                }
                else if (status == "Rejected")
                {
                    reject++;
                }
            }
            repoQ.UpdateQuestionCountComment(SubjectId, accept, reject);

            repoQ.UpdateQuestionCount(SubjectId, examSuites.Sum(es => es.Questions.Count()), examSuites.Count());

            //Response.Redirect("/#!/inactivesubjectview/" + SubjectId);
            return(SubjectId + " " + subject.SubjectName + " SUCCESS !!");
        }
Esempio n. 3
0
        public Subject GetSubject(string SubjectId)
        {
            var _subject    = repoForApprove.GetInActiveSubject(SubjectId);
            var _examSuites = repoQ.GetAllQuestionSuiteBySubjectId(SubjectId);

            var subject = new Subject
            {
                id              = _subject?._id,
                SubjectCode     = _subject?.SubjectCode,
                SubjectName     = _subject?.SubjectName,
                ContentLanguage = _subject?.ContentLanguage,
                Version         = string.Empty,
                IsDisabled      = false,
                ExamSuites      = _examSuites?.Select(es =>
                {
                    var _questionCount       = es.Questions?.Count() ?? 0;
                    var _ConsiderationStatus = repoForApprove.GetConsiderationStatus(es);

                    return(new ExamSuiteDetail
                    {
                        id = es._id,
                        TitleCode = es.Code,
                        TitleName = es.Title,
                        QuestionCount = _questionCount,
                        ConsiderationStatus = _ConsiderationStatus,
                    });
                }),
                ExamSuiteGroups = _subject?.ExamSuiteGroups?.Select(esg => new ExamSuiteGroup
                {
                    id = esg._id,
                    ExamSuiteGroupName = esg.ExamSuiteGroupName,
                    IsUsed             = esg.IsUsed,
                    PassScore          = esg.PassScore ?? 0,
                    ExamDuration       = esg.ExamDuration ?? 0,
                    QuestionCount      = 0,
                    ExamSuiteGroupMaps = esg.ExamSuiteGroupMaps.Select(esgm => new ExamSuiteGroupMap
                    {
                        id               = esgm._id,
                        ExamSuiteId      = esgm.ExamSuiteId,
                        RandomCount      = esgm.RandomCount,
                        ExamSuiteGroupId = esg._id,
                        SubjectId        = _subject?._id,
                    }),
                    SubjectId = _subject?._id,
                }),
                VersionList       = null,
                VoiceLanguageList = null, //TODO : add VoiceLanguageList
            };

            return(subject);
        }
        public InactiveApiResponse ActivateSubject(string SubjectId, string ActivateOption)
        {
            // ActivateOption : New ExamSuite Mode: , New or replace ExamSuite Mode , Replace Subject Mode:

            //InActive.SubjectId IS InActive.SubjectCode
            var    siteId           = HomeController._centerdata.SiteId;
            var    _inActiveSubject = repoForApprove.GetInActiveSubject(SubjectId);
            string SubjectCode      = _inActiveSubject.SubjectCode;
            var    now = DateTime.Now;

            if (_inActiveSubject == null)
            {
                return(new InactiveApiResponse {
                    Message = "ไม่มีวิชานี้", Code = InactiveApiResponse.ResponseCode.noinactivesubject
                });
            }

            //get ActivedSubject
            var _activatedSubject = repoForApprove.GetActivatedSubjectBySubjectCode(SubjectCode, _inActiveSubject.ContentLanguage);

            if (_activatedSubject == null)
            {
                _activatedSubject = new ViewModels.ExamBankModelsBack.ShareData.ActivatedSubject
                {
                    _id                = repoForApprove.GetNewGuid("").ToString(),
                    SubjectCode        = SubjectCode,
                    SiteId             = siteId,
                    CreateDateTime     = now,
                    LastUpdateDateTime = now,
                    IsEReadiness       = false,
                    DisabledDateTime   = null,
                    SubjectId          = "",//จะถูกใส่ตอน Upsert
                    ContentLanguage    = _inActiveSubject.ContentLanguage,
                };
            }

            //Get InActive for Convert
            var _inActiveExamSuite = repoQ.GetAllQuestionSuiteBySubjectId(SubjectId);
            //get old Subject
            var _oldSubject = repoForApprove.GetSubject(_activatedSubject.SubjectId);

            //var inActCtrl = new InActiveController(repoForApprove, null, null);
            foreach (var es in _inActiveExamSuite)
            {
                if (repoForApprove.GetConsiderationStatus(es) == "Wait")
                {
                    return(new InactiveApiResponse {
                        Message = "ยังตรวจข้อสอบไม่ครบ", Code = InactiveApiResponse.ResponseCode.notacceptallquestion
                    });
                }
                else if (repoForApprove.GetConsiderationStatus(es) == "Rejected")
                {
                    return(new InactiveApiResponse {
                        Message = "มีข้อสอบที่ถูกปฏิเสธ", Code = InactiveApiResponse.ResponseCode.notacceptallquestion
                    });
                }
            }

            // New ExamSuite Mode
            if (ActivateOption == "INS")
            {
                // Check ต้องเป็น suite ใหม่ทั้งหมด ถ้ามี return false
                var _allNewTitleCode = _inActiveExamSuite.Select(x => x.Code)?.ToList();
                //if has exist
                var isExistExamSuite = _oldSubject?.ExamSuites?.Any(es => _allNewTitleCode?.Any(code => code == es.TitleCode) ?? true) ?? false;
                if (isExistExamSuite)
                {
                    return(new InactiveApiResponse {
                        Message = "ไม่สามารถเริ่มใช้รายวิชาได้ เนื่องจากมีหมวดข้อสอบซ้ำกันในรายวิชาที่เริ่มใช้งานอยู่แล้ว", Code = InactiveApiResponse.ResponseCode.existingexamsuite
                    });
                }
            }


            var _newQuestion           = new List <Activated.Question>();
            var _newSubject            = this.ConvertToActivatedSubject(_inActiveSubject, _inActiveExamSuite, now, out _newQuestion);
            var _lastestSubjectVersion = repoForApprove.ListSubjectBySubjectCode(_activatedSubject.SubjectCode, _newSubject.ContentLanguage)
                                         ?.OrderByDescending(sub => sub.CreateDateTime)
                                         ?.FirstOrDefault()?.Version ?? this.ManageVersion(string.Empty, VersionModifyOption.InitialVersion);

            //Update ActivedSubject
            _activatedSubject.SubjectId = _newSubject._id;

            if (_oldSubject == null)
            {
                //Update Version
                _newSubject.Version = this.ManageVersion(string.Empty, VersionModifyOption.InitialVersion);
                //Create ActivedSubject
                repoForApprove.CreateActivatedSubject(_activatedSubject);
            }
            // New ExamSuite Mode
            // New or replace ExamSuite Mode (upsert)
            else if (ActivateOption == "INS" || ActivateOption == "UPS")
            {
                // Add Old suite
                var _newSuite       = _newSubject.ExamSuites.Where(x => _oldSubject.ExamSuites.All(y => y.TitleCode != x.TitleCode))?.ToList();
                var _oldAndDupSuite = _oldSubject.ExamSuites.Except(_newSuite)?.ToList();
                var _oldSuite       = _oldAndDupSuite.Where(x => _newSubject.ExamSuites.All(y => y.TitleCode != x.TitleCode))?.ToList();
                //_newSubject.ExamSuites = _oldAndDupSuite.Concat(_newSuite).ToList();
                _newSubject.ExamSuites.AddRange(_oldSuite);

                //add old group
                var _oldGroup        = _oldSubject.ExamSuiteGroups.Where(x => _newSubject.ExamSuiteGroups.All(y => y._id != x._id))?.ToList();
                var _dupGroupFromNew = _newSubject.ExamSuiteGroups.Where(og => _oldSubject.ExamSuiteGroups.Any(ng => ng._id == og._id))?.ToList();
                //var _newGroup = _newSubject.ExamSuiteGroups.Except(_oldSubject.ExamSuiteGroups);
                //var _newAndDupGroup = _newSubject.ExamSuiteGroups.Except(_oldGroup);
                var _newGroup = _newSubject.ExamSuiteGroups.Where(x => _oldSubject.ExamSuiteGroups.All(y => y._id != x._id))?.ToList();

                //add new map to _oldGroup
                foreach (var group in _oldGroup)
                {
                    group.ExamSuiteGroupMaps.AddRange(_newSuite.Select(es => new Activated.ExamSuiteGroupMap()
                    {
                        _id         = Guid.NewGuid().ToString(),
                        ExamSuiteId = es._id,
                        RandomCount = 0,
                    }).ToList());
                }

                //add old map to _dupGroupFromNew
                foreach (var group in _dupGroupFromNew)
                {
                    group.ExamSuiteGroupMaps.AddRange(_oldSuite.Select(es => new Activated.ExamSuiteGroupMap()
                    {
                        _id         = Guid.NewGuid().ToString(),
                        ExamSuiteId = es._id,
                        RandomCount = _oldSubject.ExamSuiteGroups?.Select(g => g.ExamSuiteGroupMaps?.FirstOrDefault(m => m.ExamSuiteId == es._id))?.FirstOrDefault()?.RandomCount ?? 0,
                    }).ToList());
                }

                //add old map to _newGroup
                foreach (var group in _newGroup)
                {
                    group.ExamSuiteGroupMaps.AddRange(_oldSuite.Select(es => new Activated.ExamSuiteGroupMap()
                    {
                        _id         = Guid.NewGuid().ToString(),
                        ExamSuiteId = es._id,
                        RandomCount = 0,
                    }).ToList());
                }

                _newSubject.ExamSuiteGroups = _oldGroup.Concat(_dupGroupFromNew).Concat(_newGroup).ToList();

                //Update Version
                _newSubject.Version = this.ManageVersion(_lastestSubjectVersion, VersionModifyOption.IncreaseMinor);
                //Update ActivedSubject
                repoForApprove.UpsertActivatedSubject(_activatedSubject);
            }
            //Replace Subject Mode
            else if (ActivateOption == "REP")
            {
                //Update Version
                _newSubject.Version = ManageVersion(_lastestSubjectVersion, VersionModifyOption.IncreaseMajor);
                //Update ActivedSubject
                repoForApprove.UpdateActivatedSubject(_activatedSubject);
            }
            else
            {
                return(new InactiveApiResponse {
                    Message = "กรุณาเลือกวิธีการ Activate", Code = InactiveApiResponse.ResponseCode.nooption
                });
            }

            //All option must create newSubject and newQuestion
            repoForApprove.CreateSubject(_newSubject);
            repoForApprove.CreateQuestion(_newQuestion);

            //All option must delete InActiveSubject and Considerratio
            repoForApprove.DeleteAllInSubject(SubjectId);
            repoForApprove.DeleteAllConsiderration(_newSubject.ExamSuites.Select(es => es._id).ToList());
            return(new InactiveApiResponse {
                Message = "เริ่มใช้รายวิชาสำเร็จ", Code = InactiveApiResponse.ResponseCode.success
            });
        }