public Int32 CreatePaperTemplateOfExercise(ExaminationTask et, List<Question> readyQs)
        {
            Int32 eptId, eptqId;
            String eptQs;
            Int32[] eptQsAry;
            ExaminationPaperTemplate ept;
            ExaminationPaperTemplateQuestion eptq;
            ExaminationQuestionDone eqd;

            eptId = GetEPTId();

            eptQsAry = readyQs.Select(m => m.Q_Id).ToArray();
            eptQs = JsonConvert.SerializeObject(eptQsAry);

            ept = new ExaminationPaperTemplate
            {
                EPT_Id = eptId,
                ET_Id = et.ET_Id,
                ET_Type = et.ET_Type,
                EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Undone,
                EPT_StartDate = et.ET_StartTime.Date,
                EPT_StartTime = et.ET_StartTime, // 练习试卷模板,无需开启,故“开始时间”设置为任务定义的“开始时间”。
                EPT_EndTime = et.ET_StartTime, // 同上
                EPT_TimeSpan = et.ET_TimeSpan,
                EPT_Questions = eptQs,
                EPT_Remark = "本试卷模板由系统于" + now.ToString("yyyy年MM月dd日") + "自动生成。",
                EPT_AddTime = now,
                EPT_Status = 1
            };
            olsEni.Entry(ept).State = EntityState.Added;

            if (0 == olsEni.SaveChanges())
            {
                throw new Exception(ResponseMessage.SaveChangesError);
            }

            eptqId = GetEPTQId();

            foreach (var q in readyQs)
            {

                eptq = new ExaminationPaperTemplateQuestion
                {
                    EPTQ_Id = eptqId,
                    EPT_Id = eptId,
                    EPTQ_Type = q.Q_Type,
                    EPTQ_Classify = q.QC_Id,
                    EPTQ_Score = q.Q_Score,
                    EPTQ_Content = q.Q_Content,
                    EPTQ_OptionalAnswer = q.Q_OptionalAnswer,
                    EPTQ_ModelAnswer = q.Q_ModelAnswer,
                    EPTQ_Remark = q.Q_Remark,
                    EPTQ_AddTime = now,
                    EPTQ_Status = 1
                };
                olsEni.Entry(eptq).State = EntityState.Added;

                // 添加已出题记录
                eqd = new ExaminationQuestionDone { ET_Id = et.ET_Id, EPT_Id = ept.EPT_Id, U_Id = uId, Q_Id = q.Q_Id };
                olsEni.Entry(eqd).State = EntityState.Added;

                eptqId += 1;
            }

            if (0 == olsEni.SaveChanges())
            {
                throw new Exception(ResponseMessage.SaveChangesError);
            }

            return eptId;
        }
        private void AddPaperTemplateAndQuestionTemplate(ExaminationTask model)
        {
            Int32 id, tmpId, continueDays;
            Question q;
            ExaminationPaperTemplate ept;
            ExaminationPaperTemplateQuestion eptq;
            List<ExaminationPaperTemplateQuestion> eptqs;
            Int32[] qs;
            DateTime startDate, startTime, endTime;

            // 任务类型为“练习”或自动类型为“自动”,则不添加手动试卷模板
            if ((Byte)ExaminationTaskType.Exercise == model.ET_Type
                || (Byte)ExaminationTaskMode.Auto == model.ET_Mode)
            {
                return;
            }

            id = GetEPTId();

            // 设置“预定考试任务”的时间
            if ((Byte)ExaminationTaskMode.Custom == model.ET_Mode)
            {
                // - [201608191537]
                startDate = model.ET_StartTime.Date;

                startTime = model.ET_StartTime;
                startTime = new DateTime(startDate.Year, startDate.Month, startDate.Day, startTime.Hour, startTime.Minute, startTime.Second);
                startTime = startTime.AddMinutes(3);

                endTime = model.ET_EndTime;
                endTime = new DateTime(startDate.Year, startDate.Month, startDate.Day, endTime.Hour, endTime.Minute, endTime.Second);
                continueDays = model.ET_ContinuedDays > 0 ? model.ET_ContinuedDays - 1 : 0;
                endTime = endTime.AddDays(continueDays).AddMinutes(3);
            }
            else
            {
                startDate = now.Date;
                startTime = now;
                endTime = now;
            }

            ept = new ExaminationPaperTemplate
            {
                EPT_Id = id,
                ET_Id = model.ET_Id,
                ET_Type = model.ET_Type,
                EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Undone,
                EPT_StartDate = startDate,
                EPT_StartTime = startTime,
                EPT_EndTime = endTime,
                EPT_TimeSpan = model.ET_TimeSpan,
                EPT_Questions = model.ET_Questions,
                EPT_AddTime = now,
                EPT_Status = (Byte)Status.Available
            };
            olsEni.ExaminationPaperTemplates.Add(ept);

            qs = JsonConvert.DeserializeObject<Int32[]>(model.ET_Questions);
            eptqs = new List<ExaminationPaperTemplateQuestion>();

            // 获取试题模板Id
            id = GetEPTQId();

            for (var i = 0; i < qs.Length; i++)
            {

                tmpId = qs[i];
                q = olsEni.Questions.SingleOrDefault(m => m.Q_Id == tmpId);

                if (null != q)
                {

                    eptq = new ExaminationPaperTemplateQuestion
                    {
                        EPTQ_Id = id,
                        EPT_Id = ept.EPT_Id,
                        EPTQ_Type = q.Q_Type,
                        EPTQ_Classify = q.QC_Id,
                        EPTQ_DifficultyCoefficient = q.Q_DifficultyCoefficient,
                        EPTQ_Score = q.Q_Score,
                        EPTQ_Content = q.Q_Content,
                        EPTQ_OptionalAnswer = q.Q_OptionalAnswer,
                        EPTQ_ModelAnswer = q.Q_ModelAnswer,
                        EPTQ_Remark = q.Q_Remark,
                        EPTQ_AddTime = now,
                        EPTQ_Status = q.Q_Status
                    };

                    eptqs.Add(eptq);

                    id += 1;
                }
            }

            eptqs = AdjustScore(eptqs, model.ET_StatisticType, model.ET_TotalScore);

            if (0 == olsEni.SaveChanges())
            {
                throw new Exception(ResponseMessage.SaveChangesError);
            }

            foreach (var eptq1 in eptqs)
            {
                olsEni.Entry(eptq1).State = EntityState.Added;
            }

            if (0 == olsEni.SaveChanges())
            {
                throw new Exception(ResponseMessage.SaveChangesError);
            }
        }
        private Boolean CreatePaperTemplate(ExaminationTask et, List<Question> readyQs)
        {
            Int32 eptId, eptqId;
            String eptQs;
            DateTime startTime, endTime;
            Int32[] eptQsAry;
            ExaminationPaperTemplate ept;
            ExaminationPaperTemplateQuestion eptq;
            ExaminationQuestionDone eqd;

            List<ExaminationPaperTemplateQuestion> tmpEPTQ = new List<ExaminationPaperTemplateQuestion>();

            eptId = GetEPTId();

            eptQsAry = readyQs.Select(m => m.Q_Id).ToArray();
            eptQs = JsonConvert.SerializeObject(eptQsAry);

            startTime = et.ET_StartTime;
            startTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, startTime.Hour, startTime.Minute, startTime.Second);

            endTime = et.ET_EndTime;
            endTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, endTime.Hour, endTime.Minute, endTime.Second);

            ept = new ExaminationPaperTemplate
            {
                EPT_Id = eptId,
                ET_Id = et.ET_Id,
                ET_Type = et.ET_Type,
                EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Undone,
                EPT_StartDate = nowDate,
                EPT_StartTime = startTime,
                EPT_EndTime = endTime,
                EPT_TimeSpan = et.ET_TimeSpan,
                EPT_Questions = eptQs,
                EPT_Remark = "本试卷模板由系统于" + now.ToString("yyyy年MM月dd日") + "自动生成。",
                EPT_AddTime = now,
                EPT_Status = 1
            };
            olsEni.Entry(ept).State = EntityState.Added;

            if (0 == olsEni.SaveChanges())
            {
                throw new Exception(ResponseMessage.SaveChangesError);
            }

            eptqId = GetEPTQId();

            foreach (var q in readyQs)
            {

                eptq = new ExaminationPaperTemplateQuestion
                {
                    EPTQ_Id = eptqId,
                    EPT_Id = eptId,
                    EPTQ_Type = q.Q_Type,
                    EPTQ_Classify = q.QC_Id,
                    EPTQ_Score = q.Q_Score,
                    EPTQ_Content = q.Q_Content,
                    EPTQ_OptionalAnswer = q.Q_OptionalAnswer,
                    EPTQ_ModelAnswer = q.Q_ModelAnswer,
                    EPTQ_Remark = q.Q_Remark,
                    EPTQ_AddTime = now,
                    EPTQ_Status = 1
                };
                tmpEPTQ.Add(eptq);
                olsEni.Entry(eptq).State = EntityState.Added;

                // 添加已出题记录
                eqd = new ExaminationQuestionDone { ET_Id = et.ET_Id, EPT_Id = ept.EPT_Id, Q_Id = q.Q_Id };
                olsEni.Entry(eqd).State = EntityState.Added;

                eptqId += 1;
            }

            if (0 == olsEni.SaveChanges())
            {
                throw new Exception(ResponseMessage.SaveChangesError);
            }

            return true;
        }