PureCloudRESTService.WebServicesImplementation.SQLGetAccount C# (CSharp) Method

SQLGetAccount() private method

private SQLGetAccount ( string query ) : Account
query string
return inin.Bridge.WebServices.Datadip.Lib.Account
        private Account SQLGetAccount(string query)
        {
            using (SqlConnection connection = new SqlConnection(config.connectionString))
            {
                Account account = new Account();
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    if (reader.Read())
                    {
                        // Loop through a list of contact fields that are configured and add them to the return object
                        foreach (string field in config.accountConfig.fields)
                        {
                            try
                            {
                                account.GetType().GetProperty(field).SetValue(account, reader[field], null);
                            }
                            catch (Exception ex)
                            {
                                throw new WebFaultException<string>(String.Format("Column <{0}> not found in query results: {1}", field, ex.Message), HttpStatusCode.InternalServerError);
                            }
                        }
                        // Get all the phone numbers
                        account.PhoneNumbers = getPhoneNumbers(reader, config.accountConfig.phoneCount, config.accountConfig.phoneMappings);
                        // Get all the email addresses
                        account.EmailAddresses = getEmails(reader, config.accountConfig.emailCount, config.accountConfig.emailMappings);
                        // Get the address
                        if (config.accountConfig.getAddress)
                        {
                            account.Addresses.Address.Add(getAddress(reader, config.accountConfig.addressFields));
                        }
                    }
                    else
                    {
                        throw new WebFaultException<string>("No results found", HttpStatusCode.NoContent);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    reader.Close();
                }
                return account;
            }
        }