/// <summary> /// 添加老师子表、学科关系 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool InsertTeacherDetail(TeacherModel model) { bool add = false; T_TeacherInfo_Detail detail = new T_TeacherInfo_Detail(); detail.Teacher_ID = model.ID; detail.System_Station_ID = model.System_Station_ID; detail.AddTime = model.AddTime; detail.AddPerson = model.AddPerson; detail.Valid = model.Valid; int id2 = (int)Orm.Insert(detail, true); if (id2 > 0) { //添加子表成功,添加老师学科关系 if (model.Teacher_DisciplineIds != null && model.Teacher_DisciplineIds.Length > 0) { string[] dics = model.Teacher_DisciplineIds.Split(','); if (dics.Length > 0) { T_TeacherInfo_Detail_Discipline teacherD_Dis = null; foreach (string disciplineId in dics) { if (string.IsNullOrEmpty(disciplineId)) { continue; } teacherD_Dis = new T_TeacherInfo_Detail_Discipline(); teacherD_Dis.TeacherDetail_ID = id2; teacherD_Dis.System_Station_ID = model.System_Station_ID; teacherD_Dis.Discipline_ID = int.Parse(disciplineId); teacherD_Dis.AddTime = model.AddTime; teacherD_Dis.AddPerson = model.AddPerson; //添加老师所教学科 Orm.Insert(teacherD_Dis); } } } add = true; } else { throw new ApiException("添加老师详细表失败!"); } return(add); }
/// <summary> /// 修改老师 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool TeacherUpdate(TeacherModel model) { if (model.System_Station_ID == 0) { throw new ApiException("机构ID不存在!"); } if (model.TeacherDetail_ID == 0) { throw new ApiException("TeacherDetail_ID不能为空!"); } if (string.IsNullOrEmpty(model.Name)) { throw new ApiException("姓名不能为空!"); } if (string.IsNullOrEmpty(model.CardNo)) { //throw new ApiException("身份证不能为空!"); } else { string CardNumRegexStr = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"; if (!Regex.IsMatch(model.CardNo, CardNumRegexStr)) { throw new ApiException("身份证格式不正确!"); } } //根据老师详细ID查询老师 TeacherModel teacherModel = SqlMapper.QueryForObject <TeacherModel>("GetTeacherByWhere", new { CardNo = "", Phone = "", System_Station_ID = model.System_Station_ID, TeacherDetail_ID = model.TeacherDetail_ID }); if (teacherModel == null) { throw new ApiException("老师不存在,TeacherDetail_ID是否正确!"); } //如果身份证有变更 if ((!string.IsNullOrEmpty(model.CardNo)) && model.CardNo != teacherModel.CardNo) { //判断身份证是否已使用 T_TeacherInfo teacher = SqlMapper.QueryForObject <T_TeacherInfo>("GetTeacherByCardOrPhone", new { CardNo = model.CardNo, Phone = "" }); if (teacher != null) { throw new ApiException("身份证已存在,姓名为:" + teacher.Name); } } //如果手机号有变更 if (model.Phone != teacherModel.Phone) { //判断身份证是否已使用 T_TeacherInfo teacher = SqlMapper.QueryForObject <T_TeacherInfo>("GetTeacherByCardOrPhone", new { CardNo = "", Phone = model.Phone }); if (teacher != null) { throw new ApiException("手机号已存在,姓名为:" + teacher.Name); } } bool update = false; try { SqlMapper.BeginTransaction();//开启事务 int updateTeacher = SqlMapper.Update("TeacherUpdate", new { Name = model.Name, Sex = model.Sex, CardNo = model.CardNo, JobTitle = model.JobTitle, HeadImage = model.HeadImage, Phone = model.Phone, Email = model.Email, Birthday = model.Birthday, Address = model.Address, Education_ID = model.Education_ID, GraduateSchool = model.GraduateSchool, Introduction = model.Introduction, ID = model.ID, System_Station_ID = model.System_Station_ID }); if (updateTeacher > 0) { //删除老师学科关系 SqlMapper.Delete("DeleteTeacherDiscipline", new { TeacherDetail_ID = model.TeacherDetail_ID, System_Station_ID = model.System_Station_ID }); //添加老师学科关系 if (model.Teacher_DisciplineIds != null && model.Teacher_DisciplineIds.Length > 0) { string[] dics = model.Teacher_DisciplineIds.Split(','); if (dics.Length > 0) { T_TeacherInfo_Detail_Discipline teacherD_Dis = null; foreach (string disciplineId in dics) { if (string.IsNullOrEmpty(disciplineId)) { continue; } teacherD_Dis = new T_TeacherInfo_Detail_Discipline(); teacherD_Dis.TeacherDetail_ID = model.TeacherDetail_ID; teacherD_Dis.System_Station_ID = model.System_Station_ID; teacherD_Dis.Discipline_ID = int.Parse(disciplineId); teacherD_Dis.AddTime = model.AddTime; teacherD_Dis.AddPerson = model.AddPerson; //添加老师所教学科 Orm.Insert(teacherD_Dis); } } } update = true; } else { throw new ApiException("修改老师信息失败!"); } SqlMapper.CommitTransaction(); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw new ApiException(ex.Message); } finally { //SqlMapper.CloseConnection(); } return(update); }