public Guid CreateOrUpdateContact(Contact contact, bool isDonation) // This is shit but we need a way of knowing whether to set membership specific fields
        {
            this._tracer.Trace("Method: BaseController.CreateOrUpdateContact");

            Guid             contactId = default(Guid);
            ContactMatchCode code      = contact.MatchCode;

            if (code == ContactMatchCode.None)
            {
                this._tracer.Trace("MatchCode=None. Creating a new Contact");

                // create a new contact
                contactId = this.CreateContact(contact, isDonation);
                this._tracer.Trace("Contact {0} created", contact.FullName);
            }
            else
            {
                this._tracer.Trace("MatchCode={0}. Updating existing Contact", code.ToString());

                // update existing contact
                contactId = contact.ContactId;
                this.UpdateContact(contact, isDonation);
            }

            return(contactId);
        }
Example #2
0
        /// <summary>
        /// Looks for an existing contact based on their first name, last name, mobile/home phone and email address
        /// </summary>
        public Contact MatchToExistingContact(List <Contact> contacts, string mobilePhone, string homePhone, string emailAddress)
        {
            this._tracer.Trace("Method: Matcher.MatchToExistingContact");
            this._tracer.Trace("Parameters: contacts, mobilePhone={0}, homePhone={1}, emailAddress={2}", mobilePhone, homePhone, emailAddress);

            Contact          contact = new Contact();
            ContactMatchCode code    = ContactMatchCode.None;

            mobilePhone = RemoveNonAlphaNumericChars(mobilePhone);
            homePhone   = RemoveNonAlphaNumericChars(homePhone);

            // get all active contacts by first name and last name. include emailaddress1, telephone2, mobilephone then filter locally.
            List <Contact> contactsByName = (from c in contacts
                                             select new Contact
            {
                ContactId = c.ContactId,
                FirstName = c.FirstName,
                LastName = c.LastName,
                EmailAddress = c.EmailAddress,
                MobilePhone = RemoveNonAlphaNumericChars(c.MobilePhone),
                HomePhone = RemoveNonAlphaNumericChars(c.HomePhone),
                OwnerId = c.OwnerId,
                OwnerLogicalName = c.OwnerLogicalName
            }).ToList();

            if (contactsByName.Count > 0)
            {
                List <Contact> matches = new List <Contact>();

                if (!string.IsNullOrEmpty(emailAddress))
                {
                    // step 1: filter by email address
                    matches = contactsByName.Where(c => !string.IsNullOrEmpty(c.EmailAddress) && c.EmailAddress.Equals(emailAddress, StringComparison.InvariantCultureIgnoreCase)).ToList();
                    if (matches.Count > 0)
                    {
                        code = ContactMatchCode.FirstName | ContactMatchCode.LastName | ContactMatchCode.Email;
                    }
                }

                if (matches.Count == 0)
                {
                    if (!string.IsNullOrEmpty(mobilePhone))
                    {
                        // step 2: match by mobile phone number
                        matches = contactsByName.Where(c => !string.IsNullOrEmpty(c.MobilePhone) && c.MobilePhone.Equals(mobilePhone, StringComparison.InvariantCultureIgnoreCase)).ToList();
                        if (matches.Count > 0)
                        {
                            code = ContactMatchCode.FirstName | ContactMatchCode.LastName | ContactMatchCode.MobilePhone;
                        }
                    }

                    if (matches.Count == 0)
                    {
                        if (!string.IsNullOrEmpty(homePhone))
                        {
                            // step 3: match by home phone number
                            matches = contactsByName.Where(c => !string.IsNullOrEmpty(c.HomePhone) && c.HomePhone.Equals(homePhone, StringComparison.InvariantCultureIgnoreCase)).ToList();
                            if (matches.Count > 0)
                            {
                                code = ContactMatchCode.FirstName | ContactMatchCode.LastName | ContactMatchCode.HomePhone;
                            }
                        }
                    }
                }


                if (matches.Count > 0)
                {
                    contact           = matches[0];
                    contact.MatchCode = code;
                }
            }

            this._tracer.Trace("contact.MatchCode={0}", contact.MatchCode.ToString());

            return(contact);
        }