コード例 #1
0
        public static bool ValidateGenPaperStrategies(AGPDataContext db, AGPGenPaperStrategiesModel model, ModelStateDictionary ModelState)
        {
            bool error     = false;
            var  strExceed = "数量超过预期";
            var  questions = db.Questions.Include(a => a.Catalog);

            if (db.Courses.Count(a => a.CourseId == model.CourseId) == 0)
            {
                error = true;
                ModelState.AddModelError("CourseId", "未选择课程");
            }
            if (model.CatalogList.Count == 0 ||
                (from x in db.Catalogs
                 join y in model.CatalogList on x.CatalogId equals y
                 select x.CatalogId).Count() != model.CatalogList.Count)
            {
                error = true;
                ModelState.AddModelError("CatalogList", "类别不正确");
            }
            if (model.SingleSelectCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.SingleSelect))
            {
                error = true;
                ModelState.AddModelError("SingleSelectCount", strExceed);
            }
            if (model.MultiSelectCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.MultiSelect))
            {
                error = true;
                ModelState.AddModelError("MultiSelectCount", strExceed);
            }
            if (model.CheckCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.Check))
            {
                error = true;
                ModelState.AddModelError("CheckCount", strExceed);
            }
            if (model.BlankCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.Blank))
            {
                error = true;
                ModelState.AddModelError("BlankCount", strExceed);
            }
            if (model.ShortAnswerCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.SingleSelect))
            {
                error = true;
                ModelState.AddModelError("ShortAnswerCount", strExceed);
            }
            return(error);
        }
コード例 #2
0
 public static bool ValidateGenPaperStrategies(AGPDataContext db, AGPGenPaperStrategiesModel model, ModelStateDictionary ModelState)
 {
     bool error = false;
     var strExceed = "数量超过预期";
     var questions = db.Questions.Include(a => a.Catalog);
     if (db.Courses.Count(a => a.CourseId == model.CourseId) == 0)
     {
         error = true;
         ModelState.AddModelError("CourseId", "未选择课程");
     }
     if (model.CatalogList.Count == 0 ||
         (from x in db.Catalogs
          join y in model.CatalogList on x.CatalogId equals y
          select x.CatalogId).Count() != model.CatalogList.Count)
     {
         error = true;
         ModelState.AddModelError("CatalogList", "类别不正确");
     }
     if (model.SingleSelectCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.SingleSelect))
     {
         error = true;
         ModelState.AddModelError("SingleSelectCount", strExceed);
     }
     if (model.MultiSelectCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.MultiSelect))
     {
         error = true;
         ModelState.AddModelError("MultiSelectCount", strExceed);
     }
     if (model.CheckCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.Check))
     {
         error = true;
         ModelState.AddModelError("CheckCount", strExceed);
     }
     if (model.BlankCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.Blank))
     {
         error = true;
         ModelState.AddModelError("BlankCount", strExceed);
     }
     if (model.ShortAnswerCount > questions.Count(a => a.Catalog.CatalogId == model.CourseId && a.TypeId == (int)AGPDefine.QuestionType.SingleSelect))
     {
         error = true;
         ModelState.AddModelError("ShortAnswerCount", strExceed);
     }
     return error;
 }
コード例 #3
0
        public ActionResult Create(AGPGenPaperStrategiesModel model)
        {
            AddViewData();
            if (ModelState.IsValid)
            {
                var error = ActionValidateHelper.ValidateGenPaperStrategies(db, model, ModelState);
                if (error)
                {
                    ModelState.AddModelError("", "操作失败");
                    return(View(model));
                }

                var id = PaperHelper.GeneratePaper(db, User.Identity.Name, model);
                LogHelper.Log(db, User.Identity.Name, AGPDefine.LogLevelType.Info, AGPDefine.LogEventType.Insert, AGPDefine.LogObjectType.Paper, null);
                return(RedirectToAction("Details", new { id = id }));
            }

            return(View(model));
        }
コード例 #4
0
        public ActionResult Create(AGPGenPaperStrategiesModel model)
        {
            AddViewData();
            if (ModelState.IsValid)
            {
                var error = ActionValidateHelper.ValidateGenPaperStrategies(db, model, ModelState);
                if (error)
                {
                    ModelState.AddModelError("", "操作失败");
                    return View(model);
                }

                var id = PaperHelper.GeneratePaper(db, User.Identity.Name, model);
                LogHelper.Log(db, User.Identity.Name, AGPDefine.LogLevelType.Info, AGPDefine.LogEventType.Insert, AGPDefine.LogObjectType.Paper, null);
                return RedirectToAction("Details", new { id = id });
            }

            return View(model);
        }
コード例 #5
0
        public static int GeneratePaper(AGPDataContext db, string owner, AGPGenPaperStrategiesModel model)
        {
            var dict = new Dictionary <AGPDefine.QuestionType, AGPGenPaperStrategiesCountModel>();

            dict.Add(AGPDefine.QuestionType.SingleSelect, new AGPGenPaperStrategiesCountModel()
            {
                Count = model.SingleSelectCount, Point = model.SingleSelectPoint
            });
            dict.Add(AGPDefine.QuestionType.MultiSelect, new AGPGenPaperStrategiesCountModel()
            {
                Count = model.MultiSelectCount, Point = model.MultiSelectPoint
            });
            dict.Add(AGPDefine.QuestionType.Check, new AGPGenPaperStrategiesCountModel()
            {
                Count = model.CheckCount, Point = model.CheckPoint
            });
            dict.Add(AGPDefine.QuestionType.Blank, new AGPGenPaperStrategiesCountModel()
            {
                Count = model.BlankCount, Point = model.BlankPoint
            });
            dict.Add(AGPDefine.QuestionType.ShortAnswer, new AGPGenPaperStrategiesCountModel()
            {
                Count = model.ShortAnswerCount, Point = model.ShortAnswerPoint
            });

            var user  = db.Users.Single(a => a.UserName == owner);
            var paper = new Paper()
            {
                Info = new ModelDescription()
                {
                    Name = model.Name
                },
                Time       = new ModelTime(),
                Difficulty = model.DifficultyType,
                Owner      = user,
                Points     = 0
            };

            db.Papers.Add(paper);
            db.SaveChanges();

            var allQuestions = from x in db.Questions.Include(a => a.Catalog).Include(a => a.Catalog.Course)
                               where x.State == (int)AGPDefine.CommitType.Normal
                               where x.Catalog.Course.CourseId == model.CourseId
                               join y in model.CatalogList on x.Catalog.CatalogId equals y
                               orderby Guid.NewGuid().ToString()
                               select x;

            var easyQuestion   = allQuestions.Where(IsEasy.Compile());
            var middleQuestion = allQuestions.Where(IsMiddle.Compile());
            var hardQuestion   = allQuestions.Where(IsHard.Compile());

            var selectedQuestion = new List <Paper_Question_Relationship>();

            foreach (var kv in dict)
            {
                if (kv.Value.Count == 0 || kv.Value.Point == 0)
                {
                    continue;
                }

                var     easy     = (int)Math.Ceiling(kv.Value.Count * DiffAlloc[model.DifficultyType].Item1);
                var     middle   = (int)Math.Ceiling(kv.Value.Count * DiffAlloc[model.DifficultyType].Item2);
                var     hard     = kv.Value.Count - easy - middle;
                decimal perPoint = (decimal)kv.Value.Point / (decimal)kv.Value.Count;

                var middleQ = (from x in middleQuestion
                               where x.TypeId == (int)kv.Key
                               select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = perPoint
                }).Take(middle);
                var hardQ = (from x in hardQuestion
                             where x.TypeId == (int)kv.Key
                             select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = perPoint
                }).Take(hard);
                var easyQ = (from x in easyQuestion
                             where x.TypeId == (int)kv.Key
                             select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = perPoint
                }).Take(kv.Value.Count - middleQ.Count() - hardQ.Count());
                selectedQuestion.AddRange(easyQ);
                selectedQuestion.AddRange(middleQ);
                selectedQuestion.AddRange(hardQ);
            }

            foreach (var pq in selectedQuestion)
            {
                db.PQs.Add(pq);
            }

            db.Papers.Where(a => a.PaperId == paper.PaperId).Update(a => new Paper
            {
                Points = selectedQuestion.Sum(b => b.Points)
            });

            db.SaveChanges();

            return(paper.PaperId);
        }
コード例 #6
0
ファイル: PaperHelper.cs プロジェクト: bajdcc/AutoGenPaper
        public static int GeneratePaper(AGPDataContext db, string owner, AGPGenPaperStrategiesModel model)
        {
            var dict = new Dictionary<AGPDefine.QuestionType, AGPGenPaperStrategiesCountModel>();
            dict.Add(AGPDefine.QuestionType.SingleSelect, new AGPGenPaperStrategiesCountModel() { Count = model.SingleSelectCount, Point = model.SingleSelectPoint });
            dict.Add(AGPDefine.QuestionType.MultiSelect, new AGPGenPaperStrategiesCountModel() { Count = model.MultiSelectCount, Point = model.MultiSelectPoint });
            dict.Add(AGPDefine.QuestionType.Check, new AGPGenPaperStrategiesCountModel() { Count = model.CheckCount, Point = model.CheckPoint });
            dict.Add(AGPDefine.QuestionType.Blank, new AGPGenPaperStrategiesCountModel() { Count = model.BlankCount, Point = model.BlankPoint });
            dict.Add(AGPDefine.QuestionType.ShortAnswer, new AGPGenPaperStrategiesCountModel() { Count = model.ShortAnswerCount, Point = model.ShortAnswerPoint });

            var user = db.Users.Single(a => a.UserName == owner);
            var paper = new Paper()
            {
                Info = new ModelDescription() { Name = model.Name },
                Time = new ModelTime(),
                Difficulty = model.DifficultyType,
                Owner = user,
                Points = 0
            };
            db.Papers.Add(paper);
            db.SaveChanges();

            var allQuestions = from x in db.Questions.Include(a => a.Catalog).Include(a => a.Catalog.Course)
                               where x.State == (int)AGPDefine.CommitType.Normal
                               where x.Catalog.Course.CourseId == model.CourseId
                               join y in model.CatalogList on x.Catalog.CatalogId equals y
                               orderby Guid.NewGuid().ToString()
                               select x;

            var easyQuestion = allQuestions.Where(IsEasy.Compile());
            var middleQuestion = allQuestions.Where(IsMiddle.Compile());
            var hardQuestion = allQuestions.Where(IsHard.Compile());

            var selectedQuestion = new List<Paper_Question_Relationship>();

            foreach (var kv in dict)
            {
                if (kv.Value.Count == 0 || kv.Value.Point == 0)
                    continue;

                var easy = (int)Math.Ceiling(kv.Value.Count * DiffAlloc[model.DifficultyType].Item1);
                var middle = (int)Math.Ceiling(kv.Value.Count * DiffAlloc[model.DifficultyType].Item2);
                var hard = kv.Value.Count - easy - middle;
                decimal perPoint = (decimal)kv.Value.Point / (decimal)kv.Value.Count;

                var middleQ = (from x in middleQuestion
                               where x.TypeId == (int)kv.Key
                               select new Paper_Question_Relationship()
                               {
                                   PaperId = paper.PaperId,
                                   QuestionId = x.QuestionId,
                                   Points = perPoint
                               }).Take(middle);
                var hardQ = (from x in hardQuestion
                             where x.TypeId == (int)kv.Key
                             select new Paper_Question_Relationship()
                             {
                                 PaperId = paper.PaperId,
                                 QuestionId = x.QuestionId,
                                 Points = perPoint
                             }).Take(hard);
                var easyQ = (from x in easyQuestion
                             where x.TypeId == (int)kv.Key
                             select new Paper_Question_Relationship()
                             {
                                 PaperId = paper.PaperId,
                                 QuestionId = x.QuestionId,
                                 Points = perPoint
                             }).Take(kv.Value.Count - middleQ.Count() - hardQ.Count());
                selectedQuestion.AddRange(easyQ);
                selectedQuestion.AddRange(middleQ);
                selectedQuestion.AddRange(hardQ);
            }

            foreach (var pq in selectedQuestion)
            {
                db.PQs.Add(pq);
            }

            db.Papers.Where(a => a.PaperId == paper.PaperId).Update(a => new Paper
            {
                Points = selectedQuestion.Sum(b => b.Points)
            });

            db.SaveChanges();

            return paper.PaperId;
        }
コード例 #7
0
        public static int GeneratePaper(AGPDataContext context, string owner, AGPGenPaperStrategiesModel model)
        {
            var user  = context.Users.Single(a => a.UserName == owner);
            var sum   = model.SingleSelectPoint + model.MultiSelectPoint + model.CheckPoint + model.BlankPoint + model.ShortAnswerPoint;
            var paper = new Paper()
            {
                Info = new ModelDescription()
                {
                    Name = model.Name
                },
                Time       = new ModelTime(),
                Points     = sum,
                Difficulty = model.DifficultyType,
            };

            context.Papers.Add(paper);
            context.SaveChanges();

            var allAuestions = context.Questions.Include(a => a.Catalog)
                               .Where(a => a.Catalog.CatalogId == model.CatalogId)
                               .OrderBy(a => new Guid());
            var easyQuestion   = allAuestions.Where(IsEasy.Compile());
            var middleQuestion = allAuestions.Where(IsMiddle.Compile());
            var hardQuestion   = allAuestions.Where(IsHard.Compile());

            var selectedQuestion = new List <Paper_Question_Relationship>();

            if (model.DifficultyType == 0)
            {
                int easy = 0, middle = 0, hard = 0;

                easy   = (int)(model.SingleSelectCount * 0.8);
                middle = (int)(model.SingleSelectCount * 0.1);
                hard   = model.SingleSelectCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(model.SingleSelectCount - selectedQuestion.Count()));

                easy   = (int)(model.MultiSelectCount * 0.8);
                middle = (int)(model.MultiSelectCount * 0.1);
                hard   = model.MultiSelectCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(model.MultiSelectCount - selectedQuestion.Count()));

                easy   = (int)(model.CheckCount * 0.8);
                middle = (int)(model.CheckCount * 0.1);
                hard   = model.CheckCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(model.CheckCount - selectedQuestion.Count()));

                easy   = (int)(model.BlankCount * 0.8);
                middle = (int)(model.BlankCount * 0.1);
                hard   = model.BlankCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(model.BlankCount - selectedQuestion.Count()));

                easy   = (int)(model.ShortAnswerCount * 0.8);
                middle = (int)(model.ShortAnswerCount * 0.1);
                hard   = model.ShortAnswerCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(model.ShortAnswerCount - selectedQuestion.Count()));
            }
            else if (model.DifficultyType == 1)
            {
                int easy = 0, middle = 0, hard = 0;

                easy   = (int)(model.SingleSelectCount * 0.7);
                middle = (int)(model.SingleSelectCount * 0.2);
                hard   = model.SingleSelectCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(model.SingleSelectCount - selectedQuestion.Count()));

                easy   = (int)(model.MultiSelectCount * 0.7);
                middle = (int)(model.MultiSelectCount * 0.2);
                hard   = model.MultiSelectCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(model.MultiSelectCount - selectedQuestion.Count()));

                easy   = (int)(model.CheckCount * 0.7);
                middle = (int)(model.CheckCount * 0.2);
                hard   = model.CheckCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(model.CheckCount - selectedQuestion.Count()));

                easy   = (int)(model.BlankCount * 0.7);
                middle = (int)(model.BlankCount * 0.2);
                hard   = model.BlankCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(model.BlankCount - selectedQuestion.Count()));

                easy   = (int)(model.ShortAnswerCount * 0.7);
                middle = (int)(model.ShortAnswerCount * 0.2);
                hard   = model.ShortAnswerCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(model.ShortAnswerCount - selectedQuestion.Count()));
            }
            else if (model.DifficultyType == 2)
            {
                int easy = 0, middle = 0, hard = 0;

                easy   = (int)(model.SingleSelectCount * 0.6);
                middle = (int)(model.SingleSelectCount * 0.1);
                hard   = model.SingleSelectCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.SingleSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.SingleSelectPoint / model.SingleSelectCount
                }).Take(model.SingleSelectCount - selectedQuestion.Count()));

                easy   = (int)(model.MultiSelectCount * 0.6);
                middle = (int)(model.MultiSelectCount * 0.1);
                hard   = model.MultiSelectCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect && x.Difficulty == 2
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.MultiSelect
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.MultiSelectPoint / model.MultiSelectCount
                }).Take(model.MultiSelectCount - selectedQuestion.Count()));

                easy   = (int)(model.CheckCount * 0.6);
                middle = (int)(model.CheckCount * 0.1);
                hard   = model.CheckCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check && x.Difficulty == 2
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Check
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.CheckPoint / model.CheckCount
                }).Take(model.CheckCount - selectedQuestion.Count()));

                easy   = (int)(model.BlankCount * 0.6);
                middle = (int)(model.BlankCount * 0.1);
                hard   = model.BlankCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank && x.Difficulty == 2
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.Blank
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.BlankPoint / model.BlankCount
                }).Take(model.BlankCount - selectedQuestion.Count()));

                easy   = (int)(model.ShortAnswerCount * 0.6);
                middle = (int)(model.ShortAnswerCount * 0.1);
                hard   = model.ShortAnswerCount - easy - middle;
                selectedQuestion.AddRange((from x in middleQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer && x.Difficulty == 2
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(middle));
                selectedQuestion.AddRange((from x in hardQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(hard));
                selectedQuestion.AddRange((from x in easyQuestion
                                           where x.TypeId == (int)AGPDefine.QuestionType.ShortAnswer
                                           select new Paper_Question_Relationship()
                {
                    PaperId = paper.PaperId,
                    QuestionId = x.QuestionId,
                    Points = (decimal)model.ShortAnswerPoint / model.ShortAnswerCount
                }).Take(model.ShortAnswerCount - selectedQuestion.Count()));
            }
            foreach (var pq in selectedQuestion)
            {
                context.PQs.Add(pq);
            }
            context.SaveChanges();
            return(paper.PaperId);
        }