/// <summary> /// 保存用户 /// </summary> /// <param name="user">用户实体</param> /// <returns></returns> public User SaveUser(User user) { Validate(user); if (GetUser(user.UserID) != null) throw new Exception("已经存在的用户"); return UserDao.Save(user); }
public IList GetByCondition(User user) { ArrayList param = new ArrayList(); string queryStr = "from User t where 1=1"; if (user.UserID != "") { queryStr += " and t.UserID=?"; param.Add(user.UserID); } if (user.UserName != "") { queryStr += " and t.UserName like ?"; param.Add("%"+user.UserName+"%"); } if (user.Role != null) { queryStr += " and t.Role=?"; param.Add(user.Role.RoleId); } if (user.Department != null) { queryStr += " and t.Department=?"; param.Add(user.Department.DepartmentID); } return HibernateTemplate.Find(queryStr ,param .ToArray () ); }
public void SaveUserTest() { User user = new User(); user.UserID = "buyer000"; user.Password = "******"; user.UserName = "******"; UserDao.Save(user); transactionManager.Commit(transactionStatus); }
public static User MapFromDTO(UserDTO dto) { User user = new User(); user.UserID = dto.UserID; user.UserName = dto.UserName; user.Department = dto.DepartmentID == null? null:ManagerFactory.DepartmentManager.GetDepartment(dto.DepartmentID); user.Role = dto.RoleId == null ? null : ManagerFactory.RoleManager.GetRole(dto.RoleId); return user; }
public static UserDTO MapToDTO(User model ) { UserDTO dto = new UserDTO(); dto.UserID = model.UserID; dto.UserName = model.UserName; dto.DepartmentID = model.Department == null ? "" : model.Department.DepartmentID; dto.DepartmentName = model.Department == null ? "" : model.Department.DepartmentName; dto.RoleId = model.Role == null ? "" : model.Role.RoleId; dto.RoleName = model.Role == null ? "" : model.Role.RoleName; return dto; }
public User SaveOrUpdate(User user) { HibernateTemplate.SaveOrUpdate(user); return user; }
public void Delete(User user) { HibernateTemplate.Delete(user); }
/// <summary> /// 更新用户 /// </summary> /// <param name="user">用户实体</param> /// <returns></returns> public User UpdateUser(User user) { return UserDao.SaveOrUpdate(user); }
/// <summary> /// 创建一个用户(返回包含默认值) /// </summary> /// <returns></returns> public User NewUser() { var user = new User(); return user; }
/// <summary> /// 获取用户 /// </summary> /// <returns></returns> public IList GetByCondition(User user) { return UserDao.GetByCondition(user); }
private void Validate(User user) { //TODO throw exception on error. }