/// <summary> /// 批量新建员工 /// </summary> /// <param name="employeeList">员工实体对象集合</param> /// <param name="tran">中间事务对象</param> /// <returns>返回处理后的员工实体对象集合</returns> public IList <Employee> Add(IList <Employee> employeeList, ICTransaction tran) { IList <Employee> newEmployeeList = new List <Employee>(); HibernateTransaction hTran = null; ISession session = null; ITransaction ihTran = null; if (tran != null) { hTran = (HibernateTransaction)tran; session = hTran.CurrentSession; } else { session = this.CurrentHibernateConfig.GetCurrentSession(); ihTran = session.BeginTransaction(); } try { bool isPass = true; if (employeeList != null) { Employee newEmployee = null; foreach (Employee employee in employeeList) { newEmployee = HibernateHelper.AddObject <Employee>(session, employee); newEmployeeList.Add(newEmployee); if (string.IsNullOrEmpty(newEmployee.EmployeeId) && isPass) { isPass = false; } } } if (ihTran != null) { if (isPass) { ihTran.Commit(); } else { ihTran.Rollback(); } HibernateHelper.FlushSession(session); } } catch (Exception ex) { if (ihTran != null) { ihTran.Rollback(); HibernateHelper.FlushSession(session); } throw new Exception(ex.Message, ex); } return(newEmployeeList); }
/// <summary> /// 批量新建部门 /// </summary> /// <param name="departmentList">部门实体对象集合</param> /// <param name="tran">事务对象</param> /// <returns>返回处理后的部门实体对象集合</returns> public IList <Department> Add(IList <Department> departmentList, ICTransaction tran) { IList <Department> newDepartmentList = new List <Department>(); HibernateTransaction hTran = null; ISession session = null; ITransaction ihTran = null; if (tran != null) { hTran = (HibernateTransaction)tran; session = hTran.CurrentSession; } else { session = this.CurrentHibernateConfig.GetCurrentSession(); ihTran = session.BeginTransaction(); } try { bool isPass = true; if (departmentList != null) { Department newDepartment = null; foreach (Department department in departmentList) { newDepartment = HibernateHelper.AddObject <Department>(session, department); newDepartmentList.Add(newDepartment); if (string.IsNullOrEmpty(newDepartment.DepartmentId) && isPass) { isPass = false; } } } if (ihTran != null) { if (isPass) { ihTran.Commit(); } else { ihTran.Rollback(); } HibernateHelper.FlushSession(session); } } catch (Exception ex) { if (ihTran != null) { ihTran.Rollback(); HibernateHelper.FlushSession(session); } throw new Exception(ex.Message, ex); } return(newDepartmentList); }