Пример #1
0
        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);
        }
Пример #2
0
        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);
        }