EventContext.CustomerCreated

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Hello,

I've added a CustomerCreatedHandler class that fires with EventContext.Current.CustomerCreated in vers 1.9.

It's purpose is to add the customer into another database...  For some reason, the only data I'm getting are the CustomerID and email fields.

        public static void CustomerCreatedHandler(object sender, CustomerEventArgs e)
        {
         ...
                cmd.CommandText = "INSERT Main(CustomerID,email,first_name,last_name,company,address1,address2,city,state,zip,country,office) VALUES(@customerid,@email,@firstname,@lastname,@company,@address1,@address2,@city,@stateprovince,@zip,@country,@office)";
                cmd.Parameters.AddWithValue("@customerID", e.Customer.CustomerId);
                cmd.Parameters.AddWithValue("@email", e.Customer.Email);
                cmd.Parameters.AddWithValue("@firstname", e.Customer.FirstName);
                cmd.Parameters.AddWithValue("@lastname", e.Customer.LastName);
                cmd.Parameters.AddWithValue("@company", e.Customer.Company);
                cmd.Parameters.AddWithValue("@address1", e.Customer.StreetAddress);
                cmd.Parameters.AddWithValue("@address2", e.Customer.StreetAddress2);
                cmd.Parameters.AddWithValue("@city", e.Customer.City);
                if (e.Customer.StateProvinceId > 0)
                {
                    StateProvince strState = IoC.Resolve<IStateProvinceService>().GetStateProvinceById(e.Customer.StateProvinceId);
                    cmd.Parameters.AddWithValue("@stateprovince", strState.Name);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@stateprovince", "");
                }
                cmd.Parameters.AddWithValue("@zip", e.Customer.ZipPostalCode);
                if (e.Customer.CountryId > 0)
                {
                    Country strCountry = IoC.Resolve<ICountryService>().GetCountryById(e.Customer.CountryId);
                    cmd.Parameters.AddWithValue("@country", strCountry.Name);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@country", "");
                }
                cmd.Parameters.AddWithValue("@office", e.Customer.PhoneNumber);
                cmd.ExecuteNonQuery();
                con.Close();


Any ideas?  Do I somehow need to commit the customer record being created?

Thanks in advance, Jim
13 years ago
Nothing to do with your question but just out of interest, when and where are you subscribing to the event?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.