//添加教职工信息 public BaseViewModel addFacultystaffInfo(FacultystaffBaseModel model) { BaseViewModel viewModel = new BaseViewModel(); try { //验证 学校 是否存在 if (_schoolInfoRepository.CheckInfo(model.SchoolCode, model.SchoolName)) { facultystaff_Info info = new facultystaff_Info(); info = _IMapper.Map <FacultystaffBaseModel, facultystaff_Info>(model); info.CreateDate = DateTime.Now; _facultystaffInfoRepository.Add(info); _userInfoRepository.AddDefault(info.IdNumber); int i = _facultystaffInfoRepository.SaveChanges(); if (i > 0) { viewModel.ResponseCode = 0; viewModel.Message = "信息添加成功"; } else { viewModel.ResponseCode = 1; viewModel.Message = "信息添加失败"; } } else { viewModel.ResponseCode = 6; viewModel.Message = "学校信息不存在"; } } catch (Exception ex) { viewModel.ResponseCode = 3; viewModel.Message = "出现异常"; } return(viewModel); }
//添加学生信息 public BaseViewModel addStudentInfo(StudentBaseModel student) { BaseViewModel viewModel = new BaseViewModel(); if (String.IsNullOrEmpty(student.Name) || String.IsNullOrEmpty(student.IdNumber) || String.IsNullOrEmpty(student.SchoolCode) || String.IsNullOrEmpty(student.GradeCode) || String.IsNullOrEmpty(student.ClassCode) || String.IsNullOrEmpty(student.PermanentAddress)) { viewModel.ResponseCode = 2; viewModel.Message = "参数信息为空"; } else { try { //验证 学校、年级、班级是否存在 if (_schoolInfoRepository.CheckInfo(student.SchoolCode, student.SchoolName)) { if (_gradeInfoRepository.CheckInfo(student.GradeCode, student.GradeName)) { if (_classInfoRepository.CheckInfo(student.ClassCode, student.ClassName)) { Student_Info info = new Student_Info(); info = _IMapper.Map <StudentBaseModel, Student_Info>(student); info.CreateDate = DateTime.Now; _studentInfoRepository.Add(info); _userInfoRepository.AddDefault(info.IdNumber);//创建默认账号 // _userInfoRepository int i = _studentInfoRepository.SaveChanges(); if (i > 0) { viewModel.ResponseCode = 0; viewModel.Message = "信息添加成功"; } else { viewModel.ResponseCode = 1; viewModel.Message = "信息添加失败"; } } else { viewModel.ResponseCode = 6; viewModel.Message = "班级信息不存在"; } } else { viewModel.ResponseCode = 5; viewModel.Message = "年级信息不存在"; } } else { viewModel.ResponseCode = 4; viewModel.Message = "学校信息不存在"; } } catch (Exception ex) { viewModel.ResponseCode = 3; viewModel.Message = "出现异常"; } } return(viewModel); }