public ActionResult <BaseViewModel> BatchChangeStudentInfo(StudentChangeInfo model) { BaseViewModel viewModel = new BaseViewModel(); viewModel = _studentService.BatchChangeStudentInfo(model); return(viewModel); }
//根据 id 批量学生 信息批量 升班 public BaseViewModel BatchChangeStudentInfo(StudentChangeInfo model) { BaseViewModel baseView = new BaseViewModel(); int i = 0, j = 0; foreach (var id in model.ids) { Student_Info info = _studentInfoRepository.getbyID(id); if (info != null) { // 保存到备份数据库 Student_Info_Delete info_Delete = new Student_Info_Delete(); info_Delete = _IMapper.Map <Student_Info, Student_Info_Delete>(info); info_Delete.id = Guid.NewGuid().ToString(); info_Delete.Student_id = info.id; info_Delete.Memo = model.Memo; _deleteStudentInfo.Add(info_Delete); int m = _deleteStudentInfo.SaveChanges(); //修改基本信息的 年级、班级信息 //获取年级信息 info.GradeCode = model.GradeCode; var grades = _gradeInfoRepository.getnameInfoBycode(model.GradeCode); if (grades != null) { info.GradeName = grades.GradeName; } //获取班级信息 var classes = _classInfoRepository.getNameInfoBycode(model.ClassCode); if (classes != null) { info.ClassName = classes.ClassName; } info.ClassCode = model.ClassCode; _studentInfoRepository.Update(info); int n = _studentInfoRepository.SaveChanges(); if (n > 0) { i++; } else { j++; } } else { j++; } } if (j > 0) { baseView.ResponseCode = 1; baseView.Message = "修改成功:" + i.ToString() + "条数据;修改失败:" + j + "条数据"; } else { baseView.ResponseCode = 0; baseView.Message = "全部修改成功共:" + i.ToString() + "条数据"; } return(baseView); }