<!--- 
ContactManager.cfc
Originally created by Ben Edwards; modified by Leon Chalnick

This CFC creates the ContactManager listener object. It is built from
the Mach-ii Listener class, which is part of the Mach-ii framework.

This forms the bulk of the 'controller' layer and generally acts as the
layer between the view and the model. It provides a 'thin interface'
between these two conceptual components of an mvc application.

The methods created in this component are used to get, request and set
information in the model (which is represented by Contact.cfc, also in
the model directory).
--->
<cfcomponent hint="ContactManager" extends="MachII.framework.Listener">

  <cffunction name="createContact" output="No">
    <cfargument name="firstName" type="string" required="false" />
    <cfargument name="lastName" type="string" required="true" default="" />
    <cfargument name="Address" type="string" required="false" default="" />
    <cfargument name="city" type="string" required="false" default="" />
    <cfargument name="state" type="string" required="false" default="" />
    <cfargument name="country" type="string" required="false" default="" />
    <cfargument name="zip" type="string" required="false" default="" />
    <cfargument name="phone" type="string" required="false" default="" />
    <cfargument name="email" type="string" required="false" default="" />
    <cfargument name="userlogin" type="string" required="true" default="" />
    <cfargument name="userPassword" type="string" required="true" default="" />
    <cfargument name="mailingList" type="boolean" required="true" default="false" />
    
    <cfset var contact = "" />
    <cfset var neweventargs = "" />

    <cfset var newContact = createobject('component','ows.38.mii_ContactMgr.model.contact') />
    <cfset newContact.saveNewContact(
      arguments.firstName,
      arguments.lastName,
      arguments.Address,
      arguments.city,
      arguments.state,
      arguments.country,
      arguments.zip,
      arguments.phone,
      arguments.email,
      arguments.userLogin,
      arguments.userPassword,
      arguments.mailingList
      ) />
    
    <cfset neweventargs = structnew() />
    <cfset announceevent('contactcreated', neweventargs) />
  </cffunction>
  
  <cffunction name="updateContact" output="No">
    <cfargument name="contactID" type="numeric" required="true" />
    <cfargument name="firstName" type="string" required="true" />
    <cfargument name="lastName" type="string" required="true" default="" />
    <cfargument name="Address" type="string" required="true" default="" />
    <cfargument name="city" type="string" required="true" default="" />
    <cfargument name="state" type="string" required="true" default="" />
    <cfargument name="country" type="string" required="true" default="" />
    <cfargument name="zip" type="string" required="true" default="" />
    <cfargument name="phone" type="string" required="true" default="" />
    <cfargument name="email" type="string" required="true" default="" />
    <cfargument name="userLogin" type="string" required="true" default="" />
    <cfargument name="userPassword" type="string" required="true" default="" />
    <cfargument name="mailingList" type="boolean" required="false" default="false" />

    <cfset var contact = createObject("component", "ows.38.mii_ContactMgr.model.contact") />
    <cfset var neweventargs = "" />
    
    <cfset contact.saveContact(
      arguments.contactID,
      arguments.firstName,
      arguments.lastName,
      arguments.Address,
      arguments.city,
      arguments.state,
      arguments.country,
      arguments.zip,
      arguments.phone,
      arguments.email,
      arguments.userLogin,
      arguments.userPassword,
      arguments.mailingList
      ) />
    <cfset neweventargs = structnew() />
    <cfset announceevent('contactUpdated', neweventargs) /> 
  </cffunction>

  <cffunction name="getContact" returntype="ows.38.mii_ContactMgr.model.Contact" output="No">
    <cfargument name="id" type="numeric" required="true" />

    <cfset var Contact = createObject('component','ows.38.mii_ContactMgr.model.contact') />
    <cfset thisContact = Contact.fetchContact( arguments.id )>
    <cfreturn thisContact />
  </cffunction>

  <cffunction name="deleteContact" output="No">
    <cfargument name="ContactID" type="numeric" required="true" />

    <cfset contact = createObject('component','ows.38.mii_ContactMgr.model.contact') />
    <cfset contact.deleteThisContact( arguments.ContactID) />
    
  </cffunction>
  
  <cffunction name="getAllContacts" returntype="query" output="No">
    <cfset contact = createObject('component', 'ows.38.mii_ContactMgr.model.contact') />
    <cfset getcontacts = contact.getAll() />
    <cfreturn variables.getContacts />
  </cffunction>

</cfcomponent>