public DataContracts.IEmployee AddPersonToCompany(int personId, int companyId) { Employee employee = null; using (var connection = new SqlConnection(base.ConnectionString)) { using (var command = new SqlCommand("sp_CompanyAddPerson", connection)) { command.Parameters.AddWithValue("@personId", personId); command.Parameters.AddWithValue("@companyId", companyId); command.CommandType = CommandType.StoredProcedure; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { employee = new Employee(); employee.CompanyId = companyId; employee.Person = new PersonAdapter().Resolve(new Person(), reader); employee.EmployeeId = Convert.ToInt32(reader["EmployeeId"]); } connection.Close(); } } return employee; }
public IEnumerable<DataContracts.IEmployee> GetAllEmployees(int companyId) { var employees = new List<IEmployee>(); using (var connection = new SqlConnection(base.ConnectionString)) { using (var command = new SqlCommand("sp_CompanyRetrieveEmployees", connection)) { command.Parameters.AddWithValue("@companyId", companyId); command.CommandType = CommandType.StoredProcedure; connection.Open(); var reader = command.ExecuteReader(); var personAdapter = new PersonAdapter(); while (reader.Read()) { var employee = new Employee(); employee.CompanyId = Convert.ToInt32(reader["companyId"]); employee.EmployeeId = Convert.ToInt32(reader["EmployeeId"]); employee.Person = personAdapter.Resolve(new Person(), reader); employees.Add(employee); } connection.Close(); } } return employees; }