public static IEnumerable <Client> GetClients() { List <Client> сlients = new List <Client>(); using (SqlConnection connection = new SqlConnection(ActualConnectionString.Get())) { SqlCommand command = new SqlCommand("GetClients"); command.CommandType = CommandType.StoredProcedure; command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Client client = new Client(); client.Id = int.Parse(reader["ID_Клиент"].ToString()); client.Passport = reader["Паспорт"].ToString(); client.FullName = reader["ФИО"].ToString(); client.Phone = reader["Телефон"].ToString(); client.AddDrivingCategory(DrivingCategoryDAO.GetClientsDrivingCategories(client)); сlients.Add(client); } } return(сlients); }
internal static Client GetClientById(int id) { using (SqlConnection connection = new SqlConnection(ActualConnectionString.Get())) { SqlCommand command = new SqlCommand("GetClientByID"); command.CommandType = CommandType.StoredProcedure; command.Connection = connection; command.Parameters.AddWithValue("@id", id); connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Client client = new Client(); client.Id = id; client.Passport = reader["Паспорт"].ToString(); client.FullName = reader["ФИО"].ToString(); client.Phone = reader["Телефон"].ToString(); client.AddDrivingCategory(DrivingCategoryDAO.GetClientsDrivingCategories(client)); return(client); } } } return(null); }
public static IEnumerable <Employee> GetEmployees() { List <Employee> employees = new List <Employee>(); using (SqlConnection connection = new SqlConnection(ActualConnectionString.Get())) { SqlCommand command = new SqlCommand("GetEmployees"); command.CommandType = CommandType.StoredProcedure; command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Employee employee = new Employee(); employee.Id = int.Parse(reader["ID_Работник"].ToString()); employee.Passport = reader["Паспорт"].ToString(); employee.FullName = reader["ФИО"].ToString(); employee.Phone = reader["Телефон"].ToString(); employee.Position = new Position(int.Parse(reader["ID_Должность"].ToString()), reader["НазваниеДолжности"].ToString()); employee.AddDrivingCategory(DrivingCategoryDAO.GetEmployeesDrivingCategories(employee)); employee.Account = AccountDAO.GetEmployeesAccaunt(employee); employees.Add(employee); } } return(employees); }