//返回类型,0:密码更改成功,1:旧密码错误,2:密码更改不成功,请重试 public int ChangePassword(int studentId, string oldPassword, string newPassword) { //IStudentDao studentDao = new StudentDao(sessionFactory); Student selectedStudent=studentDao.Get(studentId); if (selectedStudent != null) { if (oldPassword!=selectedStudent.studentPassword) { return 1; } else { selectedStudent.studentPassword = newPassword; ISystemUserDao systemUserDao = new SystemUserDao(sessionFactory); SystemUser selectedSystemUser = systemUserDao.Get(selectedStudent.studentID.ToString()); selectedSystemUser.systemUserPassword = newPassword; try { studentDao.Update(selectedStudent); systemUserDao.Update(selectedSystemUser); return 0; } catch (Exception e) { return 2; } } } else { return 2; } }
//登陆 public Domain.SystemUser Login(string id, string password) { ISystemUserDao newUserDao = new SystemUserDao(sessionFactory); SystemUser newUser = newUserDao.Get(id); if (newUser != null){ if (password == newUser.systemUserPassword){ return newUser; } else{ return null; } } else{ return null; } }
public bool AddTeacher(Domain.Teacher newTeacher) { ITeacherDao teacherDao = new TeacherDao(sessionFactory); ISystemUserDao systemUserDao = new SystemUserDao(sessionFactory); //先存入Teacher,在存入SystemUser try { int teacherId= (Int32)teacherDao.Save(newTeacher); SystemUser newSystemUser = new SystemUser { systemUserID =teacherId.ToString(), systemUserPassword = newTeacher.teacherPassword, systemUserType = 2 }; systemUserDao.Save(newSystemUser); return true; }catch(Exception e){ return false; } }
public bool AddStudent(Student newStudent) { IStudentDao studentDao = new StudentDao(sessionFactory); ISystemUserDao systemUserDao = new SystemUserDao(sessionFactory); try { int studentId=(Int32)studentDao.Save(newStudent); //先存入Student,在存入SystemUser SystemUser newSystemUser = new SystemUser { systemUserID = studentId.ToString(), systemUserPassword = newStudent.studentPassword, systemUserType = 1 }; systemUserDao.Save(newSystemUser); return true; } catch (Exception e) { return false; } }