Example #1
0
        public bool DuplicateByCourseId(long id, long newCourseId)
        {
            var courseAssessment = GetByCourseId(id);

            foreach (CourseAssessment ca in courseAssessment)
            {
                CourseAssessment caModel = new CourseAssessment();
                caModel.courseId         = newCourseId;
                caModel.title            = ca.title;
                caModel.assessmentTypeId = ca.assessmentTypeId;
                caModel.userGroupId      = ca.userGroupId;
                caModel.passingGrade     = ca.passingGrade;
                caModel.isImmediate      = ca.isImmediate;
                caModel.fromDate         = ca.fromDate;
                caModel.toDate           = ca.toDate;
                caModel.duration         = ca.duration;
                caModel.isAttempts       = ca.isAttempts;
                caModel.attempts         = ca.attempts;
                caModel.basedType        = ca.basedType;
                caModel.isShuffle        = ca.isShuffle;
                caModel.createdAt        = DateTime.Now;
                caModel.updatedAt        = DateTime.Now;
                _context.CourseAssessment.Add(caModel);
                _context.SaveChanges();

                var courseAssessmentId = caModel.id;
                foreach (CourseAssessmentItem cai in ca.CourseAssessmentItem)
                {
                    CourseAssessmentItem caiModel = new CourseAssessmentItem();
                    caiModel.courseAssessmentid = caModel.id;
                    caiModel.name                 = cai.name;
                    caiModel.duration             = cai.duration;
                    caiModel.assessmentItemTypeId = cai.assessmentItemTypeId;
                    caiModel.isShuffle            = cai.isShuffle;
                    caiModel.minLength            = cai.minLength;
                    caiModel.maxLength            = cai.maxLength;
                    caiModel.isTrue               = cai.isTrue;
                    caiModel.isFalse              = cai.isFalse;
                    caiModel.createdAt            = DateTime.Now;
                    caiModel.updatedAt            = DateTime.Now;

                    _context.CourseAssessmentItem.Add(caiModel);
                    _context.SaveChanges();

                    foreach (CourseAssessmentItemChoices caic in cai.CourseAssessmentItemChoices)
                    {
                        CourseAssessmentItemChoices caicModel = new CourseAssessmentItemChoices();
                        caicModel.courseAssessmentItemId = caiModel.id;
                        caicModel.name      = caic.name;
                        caicModel.isCorrect = caic.isCorrect;
                        _context.CourseAssessmentItemChoices.Add(caicModel);
                        _context.SaveChanges();
                    }
                }
            }
            return(true);
        }
Example #2
0
        public bool AddSection(long id, CourseAssessment request)
        {
            //  Process of adding course assessment items
            foreach (CourseAssessmentItem caiVal in request.CourseAssessmentItem)
            {
                CourseAssessmentItem cai = new CourseAssessmentItem();
                cai.courseAssessmentid = id;
                cai.name = caiVal.name;

                //  Static Entries: Based Type
                //  Default: 0 = No Limit; 1 = Exam-Based; 2 = Question-Based
                //  if based type is Question-Based
                if (request.basedType == 2)
                {
                    cai.duration = caiVal.duration;
                }

                //  if assessment item type is not Essay
                //  Defaults: 1 = Essay; 2 = Multiple Choices; 3 = True / False
                cai.assessmentItemTypeId = caiVal.assessmentItemTypeId;
                if (caiVal.assessmentItemTypeId == 2)
                {
                    cai.isShuffle = caiVal.isShuffle;
                }
                else
                {
                    cai.minLength = caiVal.minLength;
                    cai.maxLength = caiVal.maxLength;
                }

                //  Static Entries: Based Type
                //  if assessment item type is True or False
                //  Defaults: 1 = Essay; 2 = Multiple Choices; 3 = True / False
                if (caiVal.assessmentItemTypeId == 3)
                {
                    cai.isTrue  = caiVal.isTrue;
                    cai.isFalse = caiVal.isFalse;
                }
                cai.createdAt = DateTime.Now;
                cai.updatedAt = DateTime.Now;
                _context.CourseAssessmentItem.Add(cai);
                _context.SaveChanges();


                // Process assessment item choices if selected assessment item type is Multiple Choices
                if (caiVal.assessmentItemTypeId == 2)
                {
                    foreach (CourseAssessmentItemChoices caicVal in caiVal.CourseAssessmentItemChoices)
                    {
                        CourseAssessmentItemChoices caic = new CourseAssessmentItemChoices();
                        caic.courseAssessmentItemId = cai.id;
                        caic.name      = caicVal.name;
                        caic.isCorrect = caicVal.isCorrect;
                        caic.createdAt = DateTime.Now;
                        caic.updatedAt = DateTime.Now;
                        _context.CourseAssessmentItemChoices.Add(caic);
                        _context.SaveChanges();
                    }
                }
            }
            return(true);
        }