public ActionResult Edit(Models.PerformTotal.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.PerformTotalEdit.Id == 0) { var tb = new Perform.Entity.tbPerformTotal(); db.Set <Perform.Entity.tbPerformTotal>().Add(tb); if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加评价总分数据"); } } else { var tb = (from p in db.Table <Perform.Entity.tbPerformTotal>() where p.Id == vm.PerformTotalEdit.Id select p).FirstOrDefault(); if (tb != null) { if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改评价总分数据"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } } return(Code.MvcHelper.Post(error)); } }
public ActionResult Save(Models.PerformData.List vm) { using (var db = new XkSystem.Models.DbContext()) { string strTxtId = ""; string strStudentId = ""; string strTotalId = ""; //总分Id string strTotalScode = ""; //总分数据 try { strTxtId = Request["txtId"].ToString(); strStudentId = Request["txtStudentId"].ToString(); strTotalScode = Request["txtTotalScode"].ToString(); strTotalId = Request["txtTotalId"].ToString(); } catch { return(Code.MvcHelper.Post(null, Url.Action("List"), "暂无数据!")); } var txtId = strTxtId.Split(','); var txtStudentId = strStudentId.Split(','); var arrStudentIds = txtStudentId.Select(d => d.ConvertToInt()).ToList(); var txtTotalScode = strTotalScode.Split(','); var txtTotalId = strTotalId.Split(','); var tbOrg = (from p in db.Table <Course.Entity.tbOrg>() .Include(d => d.tbClass) .Include(d => d.tbYear) .Include(d => d.tbCourse) where p.Id == vm.ClassId select p).FirstOrDefault(); var tbPerformGroupIds = (from p in db.Table <Perform.Entity.tbPerformCourse>() where p.tbCourse.Id == tbOrg.tbCourse.Id && p.tbPerformGroup.tbPerform.Id == vm.PerformId && p.tbCourse.IsDeleted == false && p.tbPerformGroup.IsDeleted == false select p.tbPerformGroup.Id).ToList(); var PerformItemList = (from p in db.Table <Perform.Entity.tbPerformItem>() where tbPerformGroupIds.Contains(p.tbPerformGroup.Id) && p.tbPerformGroup.tbPerform.Id == vm.PerformId && p.tbPerformGroup.IsDeleted == false && p.IsMany == false && p.IsSelect == false orderby p.No select new Dto.PerformItem.List { Id = p.Id, PerformItemName = p.PerformItemName } ).ToList(); var list = (from p in db.Table <Perform.Entity.tbPerformData>() where p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId && p.tbPerformItem.IsDeleted == false && p.tbPerformItem.tbPerformGroup.IsDeleted == false && p.tbStudent.IsDeleted == false && p.tbCourse.IsDeleted == false && p.tbPerformItem.IsMany == false && p.tbPerformItem.IsSelect == false select p).ToList(); foreach (var item in PerformItemList) { var txtPerformItemScode = Request["txt_" + item.Id].Split(','); for (var i = 0; i < txtStudentId.Count(); i++) { if (string.IsNullOrEmpty(txtStudentId[i])) { //输入内容为空,判断是否存在Id if (string.IsNullOrEmpty(txtId[i]) == false) { //如果是有id的,那就是数据库中记录的,应该做删除 var tf = list.Where(d => d.Id == txtId[i].ConvertToInt()).FirstOrDefault(); XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("删除评价数据"); tf.IsDeleted = true; } } else { var courseid = (from p in db.Table <Course.Entity.tbOrg>().Where(d => d.Id == vm.ClassId) select p.tbCourse.Id).ToList().FirstOrDefault(); var studengid = txtStudentId[i].ConvertToInt(); var performitemscode = txtPerformItemScode[i].ConvertToDecimal(); //输入内容不为空,判断是否存在id并执行对应的操作 var countList = (from p in db.Table <Perform.Entity.tbPerformData>() where p.tbStudent.Id == studengid && p.tbCourse.Id == courseid && p.tbPerformItem.Id == item.Id select p).ToList(); if (countList.Count() > 0) { //如果有id的,执行更新操作 var tf = countList.FirstOrDefault(); XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改评价数据"); tf.InputDate = DateTime.Now; tf.Score = txtPerformItemScode[i].ConvertToDecimal(); if (string.IsNullOrEmpty(txtPerformItemScode[i].Trim())) { tf.Score = txtPerformItemScode[i].ConvertToDecimal(); tf.IsDeleted = true; } tf.tbSysUser = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId); } else { if (!string.IsNullOrEmpty(txtPerformItemScode[i].Trim())) { //没有id的,执行插入操作 var tf = new Perform.Entity.tbPerformData(); tf.InputDate = DateTime.Now; tf.Score = txtPerformItemScode[i].ConvertToDecimal(); tf.tbStudent = db.Set <Student.Entity.tbStudent>().Find(txtStudentId[i].ConvertToInt()); tf.tbCourse = db.Set <Course.Entity.tbCourse>().Find(courseid); tf.tbPerformItem = db.Set <Perform.Entity.tbPerformItem>().Find(item.Id); tf.tbSysUser = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId); db.Set <Perform.Entity.tbPerformData>().Add(tf); XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加评价数据"); } } } } } #region 保存总分 var oldTotalList = (from p in db.Table <Perform.Entity.tbPerformTotal>() where p.tbPerform.Id == vm.PerformId && p.tbCourse.Id == tbOrg.tbCourse.Id && arrStudentIds.Contains(p.tbStudent.Id) && p.tbStudent.IsDeleted == false && p.tbCourse.IsDeleted == false && p.tbPerform.IsDeleted == false select p).ToList(); foreach (var a in oldTotalList) { a.IsDeleted = true; a.UpdateTime = DateTime.Now; } var studentSumScore = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == tbOrg.tbCourse.Id && arrStudentIds.Contains(p.tbStudent.Id) && p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId && p.tbPerformItem.IsMany == false && p.tbPerformItem.IsSelect == false select new { studentId = p.tbStudent.Id, sum = p.Score * p.tbPerformItem.Rate / 100, }).ToList(); studentSumScore = (from p in studentSumScore group p by p.studentId into g select new { studentId = g.Key, sum = g.Select(d => d.sum).Sum() }).ToList(); var studentDaySumScore = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == tbOrg.tbCourse.Id && arrStudentIds.Contains(p.tbStudent.Id) && p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId && ((p.tbPerformItem.IsSelect == true && p.tbPerformItem.IsMany == true) || (p.tbPerformItem.IsMany == true && p.tbPerformItem.IsSelect == false)) group p by new { p.tbStudent.Id } into g select new { studentId = g.Key.Id, sum = g.Select(d => d.Score).Sum() }).ToList(); studentSumScore = studentSumScore.Union(studentDaySumScore).ToList(); var sumStudentScore = (from p in studentSumScore group p by p.studentId into g select new { studentId = g.Key, sum = g.Select(d => d.sum).Sum() }).ToList(); var entityAddTotal = new List <Entity.tbPerformTotal>(); foreach (var studentId in arrStudentIds) { var tfTotal = new Perform.Entity.tbPerformTotal(); var allSumScore = sumStudentScore.Where(d => d.studentId == studentId).FirstOrDefault(); if (allSumScore == null) { continue; } else { tfTotal.TotalScore = sumStudentScore.Where(d => d.studentId == studentId).FirstOrDefault().sum; tfTotal.tbPerform = db.Set <Perform.Entity.tbPerform>().Find(vm.PerformId); tfTotal.tbStudent = db.Set <Student.Entity.tbStudent>().Find(studentId); tfTotal.tbCourse = db.Set <Course.Entity.tbCourse>().Find(tbOrg.tbCourse.Id); entityAddTotal.Add(tfTotal); } } db.Set <Perform.Entity.tbPerformTotal>().AddRange(entityAddTotal); if (db.SaveChanges() > decimal.Zero) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增学习表现总分"); } #endregion return(Code.MvcHelper.Post(null, Url.Action("List", new { searchText = vm.SearchText, performId = vm.PerformId, classId = vm.ClassId }), "提交成功!")); } }
public ActionResult InputMultipleDelete(List <int> ids) { if (ids != null && ids.Any()) { using (var db = new XkSystem.Models.DbContext()) { var tbRemove = (from p in db.Table <Entity.tbPerformData>() .Include(d => d.tbCourse) .Include(d => d.tbStudent) .Include(d => d.tbPerformItem.tbPerformGroup.tbPerform) where ids.Contains(p.Id) select p).ToList(); foreach (var item in tbRemove) { item.IsDeleted = true; item.UpdateTime = DateTime.Now; } if (db.SaveChanges() > decimal.Zero) { Sys.Controllers.SysUserLogController.Insert("删除了学生表现多次分数!"); } var tb = tbRemove.FirstOrDefault(); if (tb == null) { } else { #region 保存总分 var oldTotalList = (from p in db.Table <Perform.Entity.tbPerformTotal>() where p.tbPerform.Id == tb.tbPerformItem.tbPerformGroup.tbPerform.Id && p.tbCourse.Id == tb.tbCourse.Id && p.tbStudent.Id == tb.tbStudent.Id && p.tbStudent.IsDeleted == false && p.tbCourse.IsDeleted == false && p.tbPerform.IsDeleted == false select p).ToList(); foreach (var a in oldTotalList) { a.IsDeleted = true; a.UpdateTime = DateTime.Now; } var studentSumScoreList = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == tb.tbCourse.Id && p.tbStudent.Id == tb.tbStudent.Id && p.tbPerformItem.tbPerformGroup.tbPerform.Id == tb.tbPerformItem.tbPerformGroup.tbPerform.Id && p.tbPerformItem.IsMany == false && p.tbPerformItem.IsSelect == false select new { score = p.Score, rate = p.tbPerformItem.Rate }).ToList(); var studentSumScore = 0m; if (studentSumScoreList.Count > 0) { studentSumScore = studentSumScoreList.Select(d => d.score * d.rate / 100).Sum(); } var studentSumDayScore = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == tb.tbCourse.Id && p.tbStudent.Id == tb.tbStudent.Id && p.tbPerformItem.tbPerformGroup.tbPerform.Id == tb.tbPerformItem.tbPerformGroup.tbPerform.Id && ((p.tbPerformItem.IsMany && p.tbPerformItem.IsSelect) || (p.tbPerformItem.IsMany && p.tbPerformItem.IsSelect == false)) select p.Score).DefaultIfEmpty(0).Sum(); var tfTotal = new Perform.Entity.tbPerformTotal(); tfTotal.TotalScore = studentSumScore + studentSumDayScore; tfTotal.tbPerform = db.Set <Perform.Entity.tbPerform>().Find(tb.tbPerformItem.tbPerformGroup.tbPerform.Id); tfTotal.tbStudent = db.Set <Student.Entity.tbStudent>().Find(tb.tbStudent.Id); tfTotal.tbCourse = db.Set <Course.Entity.tbCourse>().Find(tb.tbCourse.Id); db.Set <Perform.Entity.tbPerformTotal>().Add(tfTotal); if (db.SaveChanges() > decimal.Zero) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("更新学习表现总分数据"); } #endregion } } } return(Code.MvcHelper.Post()); }
public ActionResult InputMultipleEdit(Models.PerformDataDay.InputMultipleEdit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { var tbPerformItemFirst = (from p in db.Table <Entity.tbPerformItem>() where p.Id == vm.PerformItemId select p).FirstOrDefault(); if (tbPerformItemFirst == null) { return(Code.MvcHelper.Post(new List <string>() { $"【评价项目】不存在,请重试;" })); } else { var tbOldSum = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == vm.PerformCourseId && p.tbPerformItem.Id == vm.PerformItemId && p.tbStudent.Id == vm.StudentId select p.Score).ToList().Sum(); if (vm.PerformInputMultipleEdit.Id == 0) { var tb = new Entity.tbPerformData(); tb.InputDate = DateTime.Now; tb.Score = vm.PerformInputMultipleEdit.Score; tb.tbPerformItem = db.Set <Entity.tbPerformItem>().Find(vm.PerformItemId); tb.tbSysUser = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId); tb.tbStudent = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId); tb.tbCourse = db.Set <Course.Entity.tbCourse>().Find(vm.PerformCourseId); tb.tbPerformOption = db.Set <Entity.tbPerformOption>().Find(vm.PerformInputMultipleEdit.PerformOptionId); if (tb.tbPerformOption != null) { tb.Score = tb.tbPerformOption.OptionValue; } var sumScore = tb.Score + tbOldSum; if (sumScore > tbPerformItemFirst.ScoreMax.ConvertToDecimal()) { return(Code.MvcHelper.Post(new List <string>() { $"项目总分:{sumScore}累计达到上限{tbPerformItemFirst.ScoreMax},请重新输入分数;" })); } db.Set <Entity.tbPerformData>().Add(tb); if (db.SaveChanges() > decimal.Zero) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增学生多次表现分"); } } else { var tb = (from p in db.Table <Entity.tbPerformData>() where p.Id == vm.PerformInputMultipleEdit.Id select p).FirstOrDefault(); if (tb != null) { tb.Score = vm.PerformInputMultipleEdit.Score; tb.tbPerformItem = db.Set <Entity.tbPerformItem>().Find(vm.PerformItemId); tb.tbCourse = db.Set <Course.Entity.tbCourse>().Find(vm.PerformCourseId); tb.tbSysUser = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId); tb.tbStudent = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId); tb.tbPerformOption = db.Set <Entity.tbPerformOption>().Find(vm.PerformInputMultipleEdit.PerformOptionId); if (tb.tbPerformOption != null) { tb.Score = tb.tbPerformOption.OptionValue; } var sumScore = tb.Score + tbOldSum; if (sumScore > tbPerformItemFirst.ScoreMax.ConvertToDecimal()) { return(Code.MvcHelper.Post(new List <string>() { $"项目总分:{sumScore}累计达到上限{tbPerformItemFirst.ScoreMax},请重新输入分数;" })); } if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改学生多次表现分"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } #region 保存总分 var oldTotalList = (from p in db.Table <Perform.Entity.tbPerformTotal>() where p.tbPerform.Id == vm.PerformId && p.tbCourse.Id == vm.PerformCourseId && p.tbStudent.Id == vm.StudentId && p.tbStudent.IsDeleted == false && p.tbCourse.IsDeleted == false && p.tbPerform.IsDeleted == false select p).ToList(); foreach (var a in oldTotalList) { a.IsDeleted = true; a.UpdateTime = DateTime.Now; } var studentSumScoreList = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == vm.PerformCourseId && p.tbStudent.Id == vm.StudentId && p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId && p.tbPerformItem.IsMany == false && p.tbPerformItem.IsSelect == false select new { score = p.Score, rate = p.tbPerformItem.Rate }).ToList(); var studentSumScore = 0m; if (studentSumScoreList.Count > 0) { studentSumScore = studentSumScoreList.Select(d => d.score * d.rate / 100).Sum(); } var studentSumDayScore = (from p in db.Table <Entity.tbPerformData>() where p.tbCourse.Id == vm.PerformCourseId && p.tbStudent.Id == vm.StudentId && p.tbPerformItem.tbPerformGroup.tbPerform.Id == vm.PerformId && ((p.tbPerformItem.IsMany && p.tbPerformItem.IsSelect) || (p.tbPerformItem.IsMany && p.tbPerformItem.IsSelect == false)) select p.Score).Sum(); var tfTotal = new Perform.Entity.tbPerformTotal(); tfTotal.TotalScore = studentSumScore + studentSumDayScore; tfTotal.tbPerform = db.Set <Perform.Entity.tbPerform>().Find(vm.PerformId); tfTotal.tbStudent = db.Set <Student.Entity.tbStudent>().Find(vm.StudentId); tfTotal.tbCourse = db.Set <Course.Entity.tbCourse>().Find(vm.PerformCourseId); db.Set <Perform.Entity.tbPerformTotal>().Add(tfTotal); if (db.SaveChanges() > decimal.Zero) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增学习表现总分"); } #endregion } } return(Code.MvcHelper.Post(null, returnUrl: Url.Action("InputMultipleList", new { PerformId = vm.PerformId, StudentId = vm.StudentId, PerformItemId = vm.PerformItemId, PerformCourseId = vm.PerformCourseId }))); } }