public ActionResult Batch()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.ClassAllotClass.Batch();
                vm.YearList = YearController.SelectList(Code.EnumHelper.YearType.Year);
                if (vm.BatchEdit.YearId == 0 && vm.YearList.Count > 0)
                {
                    vm.BatchEdit.YearId = vm.YearList.OrderByDescending(d => d.Selected).FirstOrDefault().Value.ConvertToInt();
                }
                vm.GradeList     = GradeController.SelectList();
                vm.ClassTypeList = ClassTypeController.SelectList();

                return(View(vm));
            }
        }
        public ActionResult Batch(Models.ClassAllotClass.Batch vm)
        {
            var error = new List <string>();

            if (error.Count == decimal.Zero)
            {
                using (var db = new XkSystem.Models.DbContext())
                {
                    var tb        = db.Table <Basis.Entity.tbClassAllotClass>().ToList();
                    var grade     = db.Set <Basis.Entity.tbGrade>().Find(vm.BatchEdit.GradeId);
                    var year      = db.Set <Basis.Entity.tbYear>().Find(vm.BatchEdit.YearId);
                    var classType = db.Set <Basis.Entity.tbClassType>().Find(vm.BatchEdit.ClassTypeId);

                    var list = new List <Basis.Entity.tbClassAllotClass>();
                    for (var i = 1; i <= vm.BatchEdit.Num; i++)
                    {
                        var classAllotClass = new Basis.Entity.tbClassAllotClass()
                        {
                            ClassName   = grade.GradeName + i + "班",
                            No          = i,
                            tbGrade     = grade,
                            tbYear      = year,
                            tbClassType = classType
                        };
                        if (tb.Where(d => d.ClassName == classAllotClass.ClassName).Count() == 0)
                        {
                            list.Add(classAllotClass);
                        }
                    }

                    db.Set <Basis.Entity.tbClassAllotClass>().AddRange(list);

                    if (db.SaveChanges() > 0)
                    {
                        XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加/修改了分班方式");
                    }
                }
            }

            return(Code.MvcHelper.Post(error));
        }