using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.EvaluationManage; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.EvaluationManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using Bowin.Common.Utility; using Bowin.Common.Mapping; using EMIS.CommonLogic.SystemServices; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.EducationManagement; using EMIS.Utility; namespace EMIS.CommonLogic.EvaluationManage { public class EvaluationSettingServices : BaseServices, IEvaluationSettingServices { public EvaluationSettingDAL EvaluationSettingDAL { get; set; } public ISerialNumberServices SerialNumberServices { get; set; } public SchoolyearRepository SchoolyearRepository { get; set; } public EducationSchedulingClassRepository educationSchedulingClassRepository { get; set; } public InSchoolSettingRepository inSchoolSettingRepository { get; set; } #region 1.0 查询评价设定列表信息 public Bowin.Common.Linq.Entity.IGridResultSet GetEvaluationSettingViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? campusID, Guid? collegeID, int? openStatus, Guid? CoursematerialID, Guid? departmentID, Guid? userId, int? standardID, int? schoolyearCodeID, Guid? classmajorID,int? learningformID, int? education,string LearnSystem, int pageIndex, int pageSize) { bool hasClassmajorFilter = false; Expression> filter = x => true; Expression> classmajorFilter = x => true; if (openStatus.HasValue && openStatus >= 0) { filter = filter.And(w => w.OpenStatus == openStatus); } if (schoolYearID.HasValue && schoolYearID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID); } if (campusID.HasValue && campusID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CampusID == campusID); } if (classmajorID.HasValue && classmajorID != Guid.Empty) { hasClassmajorFilter = true; classmajorFilter = x => x.ClassmajorID == classmajorID; } if (schoolyearCodeID.HasValue && schoolyearCodeID > 0) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == schoolyearCodeID); } if (learningformID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { hasClassmajorFilter = true; var LearnSystems = Convert.ToDecimal(LearnSystem); classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } if (standardID.HasValue && standardID > 0) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (hasClassmajorFilter) { filter = filter.And(w => w.EM_EducationMissionClass.CF_Classmajor.AsQueryable().Any(classmajorFilter)); } if (collegeID.HasValue && collegeID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CollegeID == collegeID); } if (CoursematerialID.HasValue && CoursematerialID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.CoursematerialID == CoursematerialID); } if (departmentID.HasValue && departmentID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_Department.DepartmentID == departmentID); } if (userId.HasValue && userId != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_MissionClassTeacher.Any(x => x.UserID == userId)); } var query = EvaluationSettingDAL.GetEvaluationSettingQuery(filter); query = GetQueryByDataRangeByCollege(query);//以院系 区分 if ((configuretView.Attribute != "UserNames" && !string.IsNullOrEmpty(configuretView.ConditionValue)) && (configuretView.Attribute != "UserCodes" && !string.IsNullOrEmpty(configuretView.ConditionValue))) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } var educationMissionClassIDList = query.Select(x => x.EducationMissionClassID).ToList(); var missionClassTeacherList = EvaluationSettingDAL.GetMissionClassTeacherViewQueryable(x => educationMissionClassIDList.Contains(x.MissionClassID)); var result = query.OrderBy(x => x.SchoolyearCode).OrderBy(x => x.CourseCode).OrderBy(x => x.EducationMissionClassName). ToGridResultSet(pageIndex, pageSize); if (configuretView.Attribute == "UserCodes" && !string.IsNullOrEmpty(configuretView.ConditionValue)) { missionClassTeacherList = missionClassTeacherList.Where(x => x.LoginID == configuretView.ConditionValue).ToList(); var missionClassTeacherIDList = missionClassTeacherList.Select(x => x.EducationMissionClassID).ToList(); result = query.Where(x => missionClassTeacherIDList.Contains(x.EducationMissionClassID)).OrderBy(x => x.SchoolyearCode).OrderBy(x => x.CourseCode).OrderBy(x => x.EducationMissionClassName). ToGridResultSet(pageIndex, pageSize); } if (configuretView.Attribute == "UserNames" && !string.IsNullOrEmpty(configuretView.ConditionValue)) { missionClassTeacherList = missionClassTeacherList.Where(x => x.Name == configuretView.ConditionValue).ToList(); var missionClassTeacherIDList = missionClassTeacherList.Select(x => x.EducationMissionClassID).ToList(); result = query.Where(x => missionClassTeacherIDList.Contains(x.EducationMissionClassID)).OrderBy(x => x.SchoolyearCode).OrderBy(x => x.CourseCode).OrderBy(x => x.EducationMissionClassName). ToGridResultSet(pageIndex, pageSize); } result.rows.ForEach(x => x.EvaluationSettingMissionClassTeacherViewList = new HashSet(missionClassTeacherList. Where(y => y.EducationMissionClassID == x.EducationMissionClassID))); return result; } #endregion #region 2.0 查询评价设定编辑信息 public ViewModel.EvaluationManage.EvaluationSettingView GetEvaluationSettingView(Guid? id) { var result = new EvaluationSettingView(); if (id.HasValue && id != Guid.Empty) result = EvaluationSettingDAL.GetEvaluationSettingQuery(x => x.EvaluationSettingID == id).FirstOrDefault(); return result; } #endregion #region 3.0 保存评价设定数据信息 public void AddOrUpdateEvaluationSetting(ViewModel.EvaluationManage.EvaluationSettingView model) { EM_EvaluationSetting entity; var courseQuery = EvaluationSettingDAL.EducationMissionClassRepository.Entities.Where(x => x.EducationMissionClassID == model.EducationMissionClassID && x.RecordStatus == (int)CF_ApprovalStatus.Submitted) .Select(s => new { s.EducationMissionClassID, s.EM_EducationMission.CF_Department, s.EM_Coursematerial }); string YearCode = SchoolyearRepository.GetSingle(x => x.SchoolyearID == model.SchoolyearID).Code; string StrCode = courseQuery.FirstOrDefault().EM_Coursematerial.CourseCode + "(" + YearCode + ")"; string settingCode = SerialNumberServices.GetSN(StrCode);//格式20160429 #region 0.0 提取该教学任务班下对应的相关人员信息 var evaluationTableEntity = EvaluationSettingDAL.EvaluationTableRepository.GetSingle(x => x.EvaluationTableID == model.EvaluationTableID, x => x.EM_EvaluationType); if (evaluationTableEntity == null) { throw new Exception("该评价表没指定参评类型!"); } bool? IsApply = evaluationTableEntity.EM_EvaluationType.IsStudent; var evaluationByStudentUser = EvaluationSettingDAL.GetEvaluationByStudent(model.EducationMissionClassID); // var evaluationByStaffUser = EvaluationSettingDAL.GetEvaluationByStaff(model.EducationMissionClassID,null); #endregion if (model.EvaluationSettingID == Guid.Empty) { #region 1.0 评价设置基本信息 Add entity = new EM_EvaluationSetting(); model.DynamicCloneTo(entity); //SetNewStatus方法去掉了设置ID的功能 entity.EvaluationSettingID = Guid.NewGuid(); //entity.ID = Function.NewPKGuid(); SetNewStatus(entity);//EMIS.CommonLogic //是否适用于学生 否 默认同行 //if ((bool)IsApply) //{ foreach (var sysUser in evaluationByStudentUser) { entity.CF_Student.Add(sysUser); } //} //else //{ //foreach (var sysUser in evaluationByStaffUser) //{ // entity.CF_Staff.Add(sysUser); //} entity.EvaluationSettingCode = settingCode;//SerialNumberServices.SetSN(model.CourseCode + "(" + model.SchoolyearCode + ")"); entity.CreateTime = DateTime.Now; entity.RecordStatus = evaluationTableEntity.EM_EvaluationType.IsStudent == true ? (int)CF_YesOrNoStatus.Yes : (int)CF_YesOrNoStatus.No;//是否适用学生 entity.EvaluationTypeID = evaluationTableEntity.EvaluationTypeID;//参评类型 UnitOfWork.Add(entity); #endregion } else { #region 2.0 评价设置基本信息 Update entity = EvaluationSettingDAL.EvaluationSettingRepository.GetSingle(x => x.EvaluationSettingID == model.EvaluationSettingID, (x => x.CF_Student), (x => x.CF_Staff)); if (entity != null) { SetModifyStatus(entity); entity.CF_Student = new HashSet();//该学生、对应的所有数据 foreach (var sysUser in evaluationByStudentUser) { entity.CF_Student.Add(sysUser); } entity.CF_Staff = new HashSet();//该同行、对应的所有数据 //foreach (var sysUser in evaluationByStaffUser) //{ // entity.CF_Staff.Add(sysUser); //} entity.EvaluationSettingCode = settingCode; entity.EvaluationTypeID = evaluationTableEntity.EvaluationTypeID;//参评类型 entity.OpenStatus = model.OpenStatus; entity.RecordStatus = evaluationTableEntity.EM_EvaluationType.IsStudent == true ? (int)CF_YesOrNoStatus.Yes : (int)CF_YesOrNoStatus.No;//是否适用学生 UnitOfWork.Update(entity); } #endregion } UnitOfWork.Commit();//统一提交 } #endregion #region 4.0 删除评价设定数据信息 //4.0 删除评价设定信息 public void DeleteEvaluationSetting(List ids) { //var evaluationSettingList = EvaluationSettingDAL.EvaluationSettingRepository.GetList(w => ids.Contains(w.EvaluationSettingID)).ToList(); //foreach (var evaluationSetting in evaluationSettingList) //{ // if (evaluationSetting.OpenStatus == (int)CF_YesOrNoStatus.Yes) // { // throw new Exception("勾选信息包含开放状态为是,不能删除!"); // } //} UnitOfWork.Delete(w => ids.Contains(w.EvaluationSettingID)); } //同时删除进入评价记录 public void DeleteSettingWithRecord(List ids) { var evaluationSettingList = EvaluationSettingDAL.EvaluationSettingRepository.GetList(w => ids.Contains(w.EvaluationSettingID)).ToList(); foreach (var evaluationSetting in evaluationSettingList) { EM_EducationMissionClass edu = EvaluationSettingDAL.EducationMissionClassRepository.GetSingle(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID); List tablelist = EvaluationSettingDAL.EvaluationTableRepository.GetList(x => x.EM_EvaluationIntType.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(edu.TeachingModeID ?? (int)CF_TeachingMode.Theory) && x.IsEnabled == true).Select(x => x.EvaluationTableID).ToList(); List lie = EvaluationSettingDAL.evaluationEnterRepository.GetList(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID && tablelist.Contains((Guid)x.EvaluationTableID)).ToList(); if (lie != null) { List idlist = lie.Select(x => x.EvaluationEnterID).ToList(); UnitOfWork.Delete(x => idlist.Contains(x.EvaluationEnterID)); UnitOfWork.Delete(x => idlist.Contains(x.EvaluationEnterID)); } } UnitOfWork.Delete(w => ids.Contains(w.EvaluationSettingID)); } public bool DeleteValidate(List ids)//删除前提醒 { bool val = false; var evaluationSettingList = EvaluationSettingDAL.EvaluationSettingRepository.GetList(w => ids.Contains(w.EvaluationSettingID)).ToList(); foreach (var evaluationSetting in evaluationSettingList) { if (evaluationSetting.OpenStatus == (int)CF_YesOrNoStatus.Yes) { throw new Exception("勾选信息包含开放状态为是,不能删除!"); } EM_EducationMissionClass edu = EvaluationSettingDAL.EducationMissionClassRepository.GetSingle(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID); List tablelist = EvaluationSettingDAL.EvaluationTableRepository.GetList(x => x.EM_EvaluationIntType.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(edu.TeachingModeID ?? (int)CF_TeachingMode.Theory) && x.IsEnabled == true).Select(x => x.EvaluationTableID).ToList(); List lie = EvaluationSettingDAL.evaluationEnterRepository.GetList(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID && tablelist.Contains((Guid)x.EvaluationTableID)).ToList(); if (lie != null && lie.Count != 0) { val = true; } } return val; } #endregion #region 5.0 导出评价设定数据信息 //Excel导出 public IList GetEvaluationSettingViewList(ConfiguretView configuretView, Guid? schoolYearID, Guid? campusID, Guid? collegeID, int? openStatus, Guid? CoursematerialID, Guid? departmentID, Guid? userId, int? standardID, int? schoolyearCodeID, Guid? classmajorID, int? learningformID, int? education, string LearnSystem) { bool hasClassmajorFilter = false; Expression> filter = x => true; Expression> classmajorFilter = x => true; if (openStatus.HasValue&&openStatus >= 0) { filter= filter.And(w => w.OpenStatus == openStatus); } if (schoolYearID.HasValue && schoolYearID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID); } if (campusID.HasValue && campusID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CampusID == campusID); } if (classmajorID.HasValue && classmajorID != Guid.Empty) { hasClassmajorFilter = true; classmajorFilter = x => x.ClassmajorID == classmajorID; } if (schoolyearCodeID.HasValue&&schoolyearCodeID>0) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == schoolyearCodeID); } if (learningformID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { hasClassmajorFilter = true; var LearnSystems = Convert.ToDecimal(LearnSystem); classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } if (standardID.HasValue && standardID > 0) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (hasClassmajorFilter) { filter = filter.And(w => w.EM_EducationMissionClass.CF_Classmajor.AsQueryable().Any(classmajorFilter)); } if (collegeID.HasValue && collegeID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CollegeID == collegeID); } if (CoursematerialID.HasValue && CoursematerialID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_Coursematerial.CoursematerialID == CoursematerialID); } if (departmentID.HasValue && departmentID != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_Department.DepartmentID == departmentID); } if (userId.HasValue && userId != Guid.Empty) { filter = filter.And(w => w.EM_EducationMissionClass.EM_MissionClassTeacher.Any(x => x.UserID == userId)); } var query = EvaluationSettingDAL.GetEvaluationSettingQuery(filter); query = GetQueryByDataRangeByCollege(query); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } var educationMissionClassIDList = query.Select(x => x.EducationMissionClassID).ToList(); var missionClassTeacherList = EvaluationSettingDAL.GetMissionClassTeacherViewQueryable(x => educationMissionClassIDList.Contains(x.MissionClassID)); var result = query.OrderBy(o => o.CourseCode).ToList(); result.ForEach(x => x.EvaluationSettingMissionClassTeacherViewList = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID))); return result; } #endregion #region 6.0 查询评价设定明细信息 //学生明细 public IList EvaluationSettingStudentDetail(Guid? evaluationSettingID, int pageIndex, int pageSize) { var query = EvaluationSettingDAL.GetEvaluationSettingStudentDetailQuery(evaluationSettingID).OrderBy(x => x.LoginID); return query.ToList(); // return query.ToGridResultSet(pageIndex, pageSize); } //教职工明细 public IList EvaluationSettingStaffDetail(Guid? evaluationSettingID, int pageIndex, int pageSize) { var query = EvaluationSettingDAL.GetEvaluationSettingStaffDetailQuery(evaluationSettingID).OrderBy(x => x.StaffCode); return query.ToList(); // return query.ToGridResultSet(pageIndex, pageSize); } //教职工明细 public IList EvaluationSettingStaffList(ConfiguretView configuretView, Guid? evaluationSettingID) { var query = EvaluationSettingDAL.GetEvaluationSettingStaffDetailList(evaluationSettingID).OrderBy(x => x.StaffCode); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList(); } return query.ToList(); } //学生明细 public IList EvaluationSettingStudentList(ConfiguretView configuretView, Guid? evaluationSettingID) { var query = EvaluationSettingDAL.GetEvaluationSettingStudentDetailList(evaluationSettingID).OrderBy(x => x.LoginID); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList(); } return query.ToList(); } #endregion #region 7.0 创建评价设定清单信息 //以学年学期生成评价信息 public void CreateEvaluationInventory(Guid schoolyearID) { var inschoolStatus = inSchoolSettingRepository.GetList(w => w.IsSelected == true).Select(s => s.InSchoolStatusID).ToList(); #region 1.0 以学年学期缩小对应的教学任务班数据范围、统一构建学生、同行清单操作 List listEvaluationSetting = new List();//评价设定数据集合 var evaluationSetting = EvaluationSettingDAL.GetCreateInventoryQuery(schoolyearID);//提取对应的评价相关数据 List educationMissionClassIDLsit = this.GetQueryByDataRangeByCollege(evaluationSetting).ToList(); //获取所有的教学任务 var allEducationMissionClass = EvaluationSettingDAL.GetEducationMissionClassQuery(schoolyearID); var existEvaluationSettingList = this.EvaluationSettingDAL.EvaluationSettingRepository.GetList(x => x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolyearID, (x => x.EM_EducationMissionClass), (x => x.EM_EducationMissionClass.EM_MissionClassTeacher)).ToList(); var existCourseAndTeacher = (from es in existEvaluationSettingList from mct in es.EM_EducationMissionClass.EM_MissionClassTeacher select new { es.EM_EducationMissionClass.CoursematerialID, mct.UserID }).ToList(); List allEducationMissionClassList = this.GetQueryByDataRangeByCollege(allEducationMissionClass).ToList(); if (educationMissionClassIDLsit.Count() < 0) { throw new Exception("没有相关的评价生成信息!"); } string YearCode = SchoolyearRepository.GetSingle(x => x.SchoolyearID == schoolyearID).Code; List st = new List(); //所有的老师 var stall=EvaluationSettingDAL.StaffRepository.GetList(x=>x.RecordStatus==(int)SYS_STATUS.USABLE).ToList(); //同教研室的老师 #endregion #region 1.0 评价设置基本信息 Add EM_EvaluationSetting entity = null; foreach (var educationMissionEntity in educationMissionClassIDLsit) { if (educationMissionEntity.CF_Staff.FirstOrDefault() != null)//TODO:没有任课老师、将不做评价信息生成~ { #region 1.1 主体数据构建 string StrCode = educationMissionEntity.CourseCode + "(" + YearCode + ")"; //string settingCode = SerialNumberServices.SetSN(StrCode, 3);//格式20160429 慢慢慢~~~ entity = new EM_EvaluationSetting(); entity.EvaluationTypeID = null; entity.CreateTime = DateTime.Now; entity.EvaluationSettingCode = StrCode; entity.OpenStatus = (int)CF_YesOrNoStatus.No; entity.EducationMissionClassID = educationMissionEntity.EducationMissionClassID; entity.EvaluationTableID = null; entity.EvaluationSettingID = Guid.NewGuid(); SetNewStatus(entity); #endregion #region 1.2 学生清单写入 if (educationMissionEntity.CF_Student.Count() > 0) { //过滤非在校状态学生 educationMissionEntity.CF_Student = new HashSet(educationMissionEntity.CF_Student.Where(x => inschoolStatus.Contains(x.InSchoolStatusID))); educationMissionEntity.CF_Student.ForEach(x => { entity.CF_Student.Add(x); }); } #endregion #region 1.3 教师清单写入 List StaffList = educationMissionEntity.CF_Staff.ToList(); //去除已经生成过的课程 StaffList.RemoveAll(x => existCourseAndTeacher.Any(w => w.CoursematerialID == educationMissionEntity.CoursematerialID && w.UserID == x.UserID)); if (StaffList.Count > 0)//没有排课老师、直接不做同行查询 { var staffid = StaffList.Select(x => x.UserID).ToList(); //var staffDepartid=StaffList.Select(x=>x.DepartmentID).ToList(); //同开课教研室的教师 var stdepart = (from all in stall from staff in StaffList.Where(x => all.DepartmentID == x.DepartmentID && x.UserID != all.UserID) select all).ToList(); //var stdepart = stall.Where(x => x.DepartmentID == educationMissionEntity.DepartmentID&&!staffid.Contains(x.UserID)).ToList(); //var stdepartList = stall.Where(x => staffDepartid.Contains(x.DepartmentID)).ToList(); //上同一门课的教师 List stclass = new List(); //上同一门课的教师,用教学任务是否控制配置来排除是只生成提交的还是全部都生成 if (!Const.LOCAL_SETTING_MISSIONCLASS_CAN_SUBMIT_NOTEACHER) { foreach (var e in educationMissionClassIDLsit) { if (e.CoursematerialID == educationMissionEntity.CoursematerialID && e.EducationMissionID != educationMissionEntity.EducationMissionID) { List StaffLists = e.CF_Staff.ToList(); foreach (var s in StaffLists) { if (!staffid.Contains(s.UserID)) { stclass.Add(s); } } } } } else { foreach (var e in allEducationMissionClassList) { if (e.CoursematerialID == educationMissionEntity.CoursematerialID && e.EducationMissionClassID != educationMissionEntity.EducationMissionClassID) { List StaffLists = e.CF_Staff.ToList(); foreach (var s in StaffLists) { if (!staffid.Contains(s.UserID)) { stclass.Add(s); } } } } } List evaluationByStaffUser = new List(); foreach (var sd in stdepart) { evaluationByStaffUser.Add(sd); } foreach (var sc in stclass) { evaluationByStaffUser.Add(sc); } //foreach(var sdd in stdepartList) //{ // evaluationByStaffUser.Add(sdd); //} evaluationByStaffUser = evaluationByStaffUser.Distinct().ToList(); //EvaluationSettingDAL.GetEvaluationByStaff(educationMissionEntity.EducationMissionClassID, StaffList); if (evaluationByStaffUser.Count() > 0) { evaluationByStaffUser.ForEach(x => { entity.CF_Staff.Add(x); }); } StaffList.ForEach(x => existCourseAndTeacher.Add(new { educationMissionEntity.CoursematerialID, UserID = (Guid?)x.UserID })); } #endregion #region 1.4 Add实体集合 listEvaluationSetting.Add(entity); //UnitOfWork.Add(entity); #endregion } } if (listEvaluationSetting.Count > 0) { UnitOfWork.BulkInsert(listEvaluationSetting); UnitOfWork.BulkInsert(listEvaluationSetting, (x => x.CF_Student));//批量插入 UnitOfWork.BulkInsert(listEvaluationSetting, (x => x.CF_Staff)); } // UnitOfWork.Commit();//统一提交 #endregion } #endregion #region 8.0 查询对应的评价表|评价类型信息 //以教学任务班ID、查询对应的评价表、级评价类型信息 public IGridResultSet GetEvaluationSettingByEducationMissionClassID(Guid? educationMissionClassID) { var query = EvaluationSettingDAL.GetTableByEducationMissionClassID(educationMissionClassID); return query.ToGridResultSet(0, 10); } #endregion public void Save(Guid? evaluationSettingID, IList list, string SaveType) { try { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; EM_EvaluationSetting entity = EvaluationSettingDAL.EvaluationSettingRepository .GetSingle(x => x.EvaluationSettingID == evaluationSettingID, x => x.CF_Student, x => x.CF_Staff);//有多对多关系、一定要指定属性 var Userid = list.Select(x => x.UserID).ToList(); if (entity != null && SaveType.Equals("Student")) { entity.CF_Student = new HashSet();//该学生发放ID、对应的所有数据 var queryStudent = EvaluationSettingDAL.StudentRepository.Entities.Where(x => Userid.Contains(x.UserID)); foreach (var student in queryStudent) { entity.CF_Student.Add(student); } entity.ModifyUserID = curUser.UserID; UnitOfWork.Update(entity); } if (entity != null && SaveType.Equals("Staff")) { entity.CF_Staff = new HashSet(); var queryStaff = EvaluationSettingDAL.StaffRepository.Entities.Where(x => Userid.Contains(x.UserID)); foreach (var Staff in queryStaff) { entity.CF_Staff.Add(Staff); } entity.ModifyUserID = curUser.UserID; UnitOfWork.Update(entity); } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } } }