public dynamic SaveCourseNode(XkSystem.Models.DbContext db, string ids, Perform.Entity.tbPerformGroup performGroup, int performId) { //查出整个评价Id的所有组的科目列表 var tb = (from p in db.Table <Perform.Entity.tbPerformCourse>() .Include(d => d.tbPerformGroup) .Include(d => d.tbCourse) where p.tbPerformGroup.tbPerform.Id == performId && p.tbPerformGroup.IsDeleted == false select p).ToList(); //-1为虚构的根节点,要去掉 var idArr = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(d => d.ConvertToInt() != -1).Select(d => d.ConvertToInt()); //取交集,同一PerformId中的多个分组Subject不能重复,且判断GroupId不能是当前要修改的Id bool flag = tb.Where(d => d.tbPerformGroup.Id != performGroup.Id && d.tbPerformGroup.IsDeleted == false).Select(d => d.tbCourse.Id).Intersect(idArr).Count() > 0; if (flag) { return new { Status = decimal.Zero, Message = "同一评价下不同分组科目不能重复!" } } ; //修改当前分组的老数据为删除状态 foreach (var a in tb.Where(d => d.tbPerformGroup.Id == performGroup.Id)) { a.IsDeleted = true; } foreach (var id in idArr) { var temp = new Perform.Entity.tbPerformCourse(); temp.tbPerformGroup = performGroup; temp.tbCourse = db.Set <Course.Entity.tbCourse>().Find(id); db.Set <Perform.Entity.tbPerformCourse>().Add(temp); } XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加评价科目"); return(new { Status = decimal.One, Message = "操作成功!" }); }
public ActionResult Edit(Models.Perform.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { int performId = 0; var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.PerformEdit.Id == 0) { if (vm.CreateWay == "复制历史" && vm.CopyPerformId == 0) { error.AddError("请选择需要复制的历史评价设置!"); } var tb = new Perform.Entity.tbPerform(); tb.No = vm.PerformEdit.No == null?db.Table <Perform.Entity.tbPerform>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PerformEdit.No; tb.PerformName = vm.PerformEdit.PerformName; tb.tbYear = db.Set <Basis.Entity.tbYear>().Find(vm.PerformEdit.YearId); tb.IsOpen = vm.PerformEdit.IsOpen; tb.FromDate = vm.PerformEdit.FromDate; tb.ToDate = vm.PerformEdit.ToDate; db.Set <Perform.Entity.tbPerform>().Add(tb); if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加学生评价"); performId = tb.Id; #region 制历史 if (vm.CreateWay == "复制历史" && vm.CopyPerformId != 0) { var copyPerform = (from p in db.Table <Perform.Entity.tbPerform>() where p.Id == vm.CopyPerformId select p).FirstOrDefault(); var copyPerformGroupList = (from p in db.Table <Perform.Entity.tbPerformGroup>() where p.tbPerform.Id == vm.CopyPerformId select p).ToList(); var dbPerformItemList = (from p in db.Table <Perform.Entity.tbPerformItem>() where p.tbPerformGroup.tbPerform.Id == vm.CopyPerformId select p).ToList(); var dbPerformCourseList = (from p in db.Table <Perform.Entity.tbPerformCourse>() .Include(p => p.tbCourse) where p.tbPerformGroup.tbPerform.Id == vm.CopyPerformId select p).ToList(); foreach (var performGroup in copyPerformGroupList) { var pg = new Perform.Entity.tbPerformGroup(); pg.PerformGroupName = performGroup.PerformGroupName; pg.No = performGroup.No; pg.tbPerform = tb; db.Set <Perform.Entity.tbPerformGroup>().Add(pg); var copyPerformItemList = dbPerformItemList.Where(p => p.tbPerformGroup.Id == performGroup.Id).ToList(); foreach (var copyPerformItem in copyPerformItemList) { var pi = new Perform.Entity.tbPerformItem(); pi.PerformItemName = copyPerformItem.PerformItemName; pi.ScoreMax = copyPerformItem.ScoreMax; pi.Rate = copyPerformItem.Rate; pi.No = copyPerformItem.No; pi.tbPerformGroup = pg; db.Set <Perform.Entity.tbPerformItem>().Add(pi); } var copyPerformCourseList = dbPerformCourseList.Where(p => p.tbPerformGroup.Id == performGroup.Id).ToList(); foreach (var copyPerformCourse in copyPerformCourseList) { var pc = new Perform.Entity.tbPerformCourse(); pc.No = copyPerformCourse.No; pc.tbCourse = copyPerformCourse.tbCourse; pc.tbPerformGroup = pg; db.Set <Perform.Entity.tbPerformCourse>().Add(pc); } } db.SaveChanges(); } #endregion } } else { var tb = (from p in db.Table <Perform.Entity.tbPerform>() where p.Id == vm.PerformEdit.Id select p).FirstOrDefault(); if (tb != null) { performId = tb.Id; tb.No = vm.PerformEdit.No == null?db.Table <Perform.Entity.tbPerform>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PerformEdit.No; tb.PerformName = vm.PerformEdit.PerformName; tb.tbYear = db.Set <Basis.Entity.tbYear>().Find(vm.PerformEdit.YearId); tb.IsOpen = vm.PerformEdit.IsOpen; tb.FromDate = vm.PerformEdit.FromDate; tb.ToDate = vm.PerformEdit.ToDate; if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改学生评价"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } } if (Request["status"] != null) { return(Code.MvcHelper.Post(error, Url.Action("List"))); } else { return(Code.MvcHelper.Post(error, Url.Action("List", "PerformGroup", new { PerformId = performId }))); } } }