<CF_cfoDeclareMethod type="public">

<!---/// 
	This method will save the contact information to a database.
	If the con_id is zero, then a new contact is inserted.  If the 
	con_id is greater than zero, then an update is performed.
///--->

<CFIF VAL(self.con_id) EQ 0>
	<!--------------------------------------------------------------------------------------
		Add a New Contact 
	  -------------------------------------------------------------------------------------->	
	<CFTRANSACTION>

      <CFIF self.mailinglist NEQ "">
         <CFSET VARIABLES.mailinglist = 1>
      <CFELSE>
         <CFSET VARIABLES.mailinglist = 0>    
      </CFIF>  
		<CFQUERY NAME="InsertContact" DATASOURCE="#request.dsn#">
         INSERT INTO Contacts (FirstName, LastName, Address, City, State, Zip, Country,
            Email, Phone, UserLogin, UserPassword,  MailingList)
         VALUES (
            '#self.firstname#', 
            '#self.lastname#', 
            <CFIF self.Address NEQ "">'#self.Address#' <CFELSE> Null </CFIF>, 
            <CFIF self.city NEQ "">'#self.city#' <CFELSE> Null </CFIF>, 
            <CFIF self.state NEQ "">'#self.state#' <CFELSE> Null </CFIF>, 
            <CFIF self.zip NEQ "">'#self.zip#' <CFELSE> Null </CFIF>, 
            <CFIF self.country NEQ "">'#self.country#' <CFELSE> Null </CFIF>,
            <CFIF self.email NEQ "">'#self.email#' <CFELSE> Null </CFIF>, 
            <CFIF self.phone NEQ "">'#self.phone#' <CFELSE> Null </CFIF>, 
           '#self.userlogin#', '#self.userpassword#',
            #Variables.MailingList# )
      </CFQUERY>
		<CFQUERY NAME="q_contact" DATASOURCE="#request.dsn#">
			SELECT max(contactid) as new_id
			FROM	contacts
		</CFQUERY>

	</CFTRANSACTION>

	<!---/// Save New ID ///--->
	<CFSET self.con_id = q_contact.new_id>
	
<CFELSE>
	<!--------------------------------------------------------------------------------------
		Update Existing Contact 
	  -------------------------------------------------------------------------------------->
   <CFIF self.mailinglist NEQ "">
      <CFSET VARIABLES.mailinglist = 1>
   <CFELSE>
      <CFSET VARIABLES.mailinglist = 0>    
   </CFIF>  	
	<CFQUERY NAME="UpdateContact" DATASOURCE="#request.dsn#">
      UPDATE Contacts SET
         FirstName = '#self.firstName#', 
         LastName = '#self.lastName#',
         Address = <CFIF self.Address NEQ "">'#self.Address#' <CFELSE> Null </CFIF>,
         City = <CFIF self.city NEQ "">'#self.city#' <CFELSE> Null </CFIF>, 
         State = <CFIF self.state NEQ "">'#self.state#' <CFELSE> Null </CFIF>,
         Zip = <CFIF self.zip NEQ "">'#self.zip#' <CFELSE> Null </CFIF>,
         Country = <CFIF self.country NEQ "">'#self.country#' <CFELSE> Null </CFIF>,
         Email = <CFIF self.email NEQ "">'#self.email#' <CFELSE> Null </CFIF>, 
         Phone = <CFIF self.phone NEQ "">'#self.phone#' <CFELSE> Null </CFIF>, 
         UserLogin = '#self.userlogin#',
         UserPassword = '#self.userpassword#',
         MailingList = #Variables.MailingList#
       WHERE ContactID = #self.con_id#    
	</CFQUERY>
</CFIF>

