コード例 #1
0
 public ActionResult List()
 {
     using (var db = new XkSystem.Models.DbContext())
     {
         var vm = new Models.ElectiveClass.List();
         vm.ElectiveName = db.Table <Entity.tbElective>().FirstOrDefault(d => d.Id == vm.ElectiveId).ElectiveName;
         return(View(vm));
     }
 }
コード例 #2
0
        public ActionResult List(Models.ElectiveClass.List vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var classList = new List <int>();
                if (string.IsNullOrEmpty(vm.ClassIds) == false)
                {
                    classList = vm.ClassIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(d => d.ConvertToInt()).ToList();
                    classList.RemoveAll(d => d == 0);
                }

                var electiveClassList = (from p in db.Table <Entity.tbElectiveClass>()
                                         .Include(d => d.tbClass)
                                         where p.tbElective.Id == vm.ElectiveId
                                         select p).ToList();
                foreach (var a in electiveClassList.Where(d => classList.Contains(d.tbClass.Id) == false))
                {
                    a.IsDeleted = true;
                }

                foreach (var a in classList.Where(d => electiveClassList.Select(q => q.tbClass.Id).Contains(d) == false))
                {
                    var tb = new Entity.tbElectiveClass();
                    tb.tbElective = db.Set <Entity.tbElective>().Find(vm.ElectiveId);
                    tb.tbClass    = db.Set <Basis.Entity.tbClass>().Find(a);
                    db.Set <Entity.tbElectiveClass>().Add(tb);
                }

                if (db.SaveChanges() > 0)
                {
                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("设置了选课的参选班级!");
                }

                if (Request["Step"] != null)
                {
                    return(Code.MvcHelper.Post(null, Url.Action("List", "ElectiveSubject", new { ElectiveId = vm.ElectiveId })));
                }
                else
                {
                    return(Code.MvcHelper.Post(null, Url.Action("List", "Elective")));
                }
            }
        }