Esempio n. 1
0
        public Contracts.GenericListResult <Contracts.PersonReference> GetPersonMatch(string email, string firstname, string lastname, string gender, string maritalstatus, string campus, string street1, string street2, string city, string state, string postalcode, string phonehome, string phonecell, string birthdate, string matchpercentminimum, string sessionid)
        {
            Contracts.GenericListResult <Contracts.PersonReference> personReferenceList = new Contracts.GenericListResult <Contracts.PersonReference>();
            personReferenceList.Items = new List <Contracts.PersonReference>();

            // Load PersonReference object with the provided values
            Contracts.PersonReference personReferenceOriginal = new Contracts.PersonReference();
            personReferenceOriginal.BirthDate    = birthdate.Trim();
            personReferenceOriginal.Campus       = campus.Trim();
            personReferenceOriginal.City         = city.Trim();
            personReferenceOriginal.Emails       = new Contracts.GenericListResult <Contracts.EmailReference>();
            personReferenceOriginal.Emails.Items = new List <Contracts.EmailReference>();
            personReferenceOriginal.Emails.Items.Add(new Contracts.EmailReference(1, email.Trim(), "True", "1"));
            personReferenceOriginal.FirstName          = firstname.Trim();
            personReferenceOriginal.LastName           = lastname.Trim();
            personReferenceOriginal.Gender             = gender.Trim();
            personReferenceOriginal.MaritalStatus      = maritalstatus.Trim();
            personReferenceOriginal.NickName           = firstname.Trim();
            personReferenceOriginal.PhoneNumbers       = new Contracts.GenericListResult <Contracts.PhoneReference>();
            personReferenceOriginal.PhoneNumbers.Items = new List <Contracts.PhoneReference>();
            // Phone numbers are optional
            if (!String.IsNullOrEmpty(phonehome))
            {
                personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonehome.Trim()), "", "main/home"));
            }
            if (!String.IsNullOrEmpty(phonecell))
            {
                personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonecell.Trim()), "", "cell"));
            }
            personReferenceOriginal.PostalCode = postalcode.Trim();
            personReferenceOriginal.State      = state.Trim();
            personReferenceOriginal.Street1    = street1.Trim();
            personReferenceOriginal.Street2    = street2.Trim();

            // What is the minimum matching percent of a person that we will return from the function
            int matchPercentMinimum = String.IsNullOrEmpty(matchpercentminimum) ? 0 : Convert.ToInt32(matchpercentminimum);

            //  Let's determine the provided gender or stop
            int genderId = -1;

            switch (gender.ToLower())
            {
            case "male":
                genderId = 0;
                break;

            case "female":
                genderId = 1;
                break;
            }

            if (genderId == -1)
            {
                throw new Exception("Please specify a valid gender.");
            }

            // Let's use the first 2 characters in order to limit results and do more auto-matching
            string firstNameInitial = (firstname.Length > 1 ? firstname.Substring(0, 2) : firstname.Substring(0, 1));

            // Get persons by first initial, last name, gender and birthdate
            CorePersonService  cps     = new CorePersonService();
            List <core_person> persons = cps.GetList(firstNameInitial, lastname, false);

            PersonCollection pc;
            List <Person>    personList = new List <Person>();

            // Get persons with this e-mail address
            pc = new PersonCollection();
            pc.LoadByEmail(email);
            personList.AddRange((from pcbe in pc
                                 select pcbe).ToList());

            // Get persons with this phone number
            if (!String.IsNullOrEmpty(phonehome))
            {
                phonehome = PersonPhone.FormatPhone(phonehome);
                pc        = new PersonCollection();
                pc.LoadByPhone(phonehome);
                personList.AddRange((from pcbe in pc
                                     select pcbe).ToList());
            }
            if (!String.IsNullOrEmpty(phonecell))
            {
                phonecell = PersonPhone.FormatPhone(phonecell);
                pc        = new PersonCollection();
                pc.LoadByPhone(phonecell);
                personList.AddRange((from pcbe in pc
                                     select pcbe).ToList());
            }

            // Get persons with this address and first initial
            Address            address       = new Address(street1, street2, city, state, postalcode);
            CoreAddressService cas           = new CoreAddressService();
            List <int>         addressIdList = cas.GetList(address.StreetLine1, address.StreetLine2, address.PostalCode);
            Person             person        = new Person();

            // TODO: enhance Arena with LoadByAddressIDs function to improve performance
            foreach (int addressId in addressIdList)
            {
                PersonAddressCollection pac = new PersonAddressCollection();
                pac.LoadByAddressID(addressId);

                foreach (PersonAddress pa in pac)
                {
                    person = new Person(pa.PersonID);
                    if ((person.FirstName.ToLower().StartsWith(firstNameInitial.ToLower()) || person.NickName.ToLower().StartsWith(firstNameInitial.ToLower())))
                    {
                        personList.Add(person);
                    }
                }
            }

            // Remove duplicates
            personList = (from p in personList select p).Distinct().ToList();

            // Load persons over the Match Percent Minimum threshold
            List <int> personIdList = new List <int>();

            Contracts.PersonReference personReference = new Contracts.PersonReference();
            string mapMatch = String.Empty;
            int    counter  = 0;

            foreach (Person p in personList)
            {
                if ((from prl in personIdList where prl == p.PersonID select prl).Count() == 0)
                {
                    counter++;
                    personReference = ConvertPersonToPersonReference(p);
                    personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch);
                    personReference.MatchMap     = mapMatch;
                    personReference.IsExact      = "false";
                    // If Person is greater than Match Percent Minimum then check for exact match and add to
                    if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum)
                    {
                        string domain = String.Empty;
                        personReference.IsExact = IsPersonQualifiedForExact(p, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString();
                        personReference.IsExactPrimaryEmailDomain = domain;
                        personReferenceList.Items.Add(personReference);
                        personIdList.Add(personReference.PersonId);
                    }
                }
            }

            foreach (core_person cp in persons)
            {
                if ((from prl in personIdList where prl == cp.person_id select prl).Count() == 0)
                {
                    counter++;
                    person                       = new Person(cp.person_id);
                    personReference              = ConvertPersonToPersonReference(person);
                    personReference.IsExact      = "false";
                    personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch);
                    personReference.MatchMap     = mapMatch;
                    // If Person is greater than Match Percent Minimum then check for exact match
                    if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum)
                    {
                        string domain = String.Empty;
                        personReference.IsExact = IsPersonQualifiedForExact(person, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString();
                        personReference.IsExactPrimaryEmailDomain = domain;
                        personReferenceList.Items.Add(personReference);
                        personIdList.Add(personReference.PersonId);
                    }
                }
            }

            // Order filtered persons by Match Percent
            Contracts.GenericListResult <Contracts.PersonReference> personsSorted = new Contracts.GenericListResult <Contracts.PersonReference>();
            personsSorted.Items = new List <Contracts.PersonReference>();
            personsSorted.Items = (from prl in personReferenceList.Items orderby Convert.ToInt32(prl.MatchPercent) descending select prl).ToList();

            personsSorted.Max   = counter;
            personsSorted.Total = personReferenceList.Items.Count();

            return(personsSorted);
        }
        public Contracts.GenericListResult<Contracts.PersonReference> GetPersonMatch(string email, string firstname, string lastname, string gender, string maritalstatus, string campus, string street1, string street2, string city, string state, string postalcode, string phonehome, string phonecell, string birthdate, string matchpercentminimum, string sessionid)
        {
            Contracts.GenericListResult<Contracts.PersonReference> personReferenceList = new Contracts.GenericListResult<Contracts.PersonReference>();
            personReferenceList.Items = new List<Contracts.PersonReference>();

            // Load PersonReference object with the provided values
            Contracts.PersonReference personReferenceOriginal = new Contracts.PersonReference();
            personReferenceOriginal.BirthDate = birthdate.Trim();
            personReferenceOriginal.Campus = campus.Trim();
            personReferenceOriginal.City = city.Trim();
            personReferenceOriginal.Emails = new Contracts.GenericListResult<Contracts.EmailReference>();
            personReferenceOriginal.Emails.Items = new List<Contracts.EmailReference>();
            personReferenceOriginal.Emails.Items.Add(new Contracts.EmailReference(1, email.Trim(), "True", "1"));
            personReferenceOriginal.FirstName = firstname.Trim();
            personReferenceOriginal.LastName = lastname.Trim();
            personReferenceOriginal.Gender = gender.Trim();
            personReferenceOriginal.MaritalStatus = maritalstatus.Trim();
            personReferenceOriginal.NickName = firstname.Trim();
            personReferenceOriginal.PhoneNumbers = new Contracts.GenericListResult<Contracts.PhoneReference>();
            personReferenceOriginal.PhoneNumbers.Items = new List<Contracts.PhoneReference>();
            // Phone numbers are optional
            if (!String.IsNullOrEmpty(phonehome))
            {
                personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonehome.Trim()), "", "main/home"));
            }
            if (!String.IsNullOrEmpty(phonecell))
            {
                personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonecell.Trim()), "", "cell"));
            }
            personReferenceOriginal.PostalCode = postalcode.Trim();
            personReferenceOriginal.State = state.Trim();
            personReferenceOriginal.Street1 = street1.Trim();
            personReferenceOriginal.Street2 = street2.Trim();

            // What is the minimum matching percent of a person that we will return from the function
            int matchPercentMinimum = String.IsNullOrEmpty(matchpercentminimum) ? 0 : Convert.ToInt32(matchpercentminimum);

            //  Let's determine the provided gender or stop
            int genderId = -1;
            switch (gender.ToLower())
            {
                case "male":
                    genderId = 0;
                    break;
                case "female":
                    genderId = 1;
                    break;
            }

            if (genderId == -1)
            {
                throw new Exception("Please specify a valid gender.");
            }

            // Let's use the first 2 characters in order to limit results and do more auto-matching
            string firstNameInitial = (firstname.Length > 1 ? firstname.Substring(0, 2) : firstname.Substring(0, 1));

            // Get persons by first initial, last name, gender and birthdate
            CorePersonService cps = new CorePersonService();
            List<core_person> persons = cps.GetList(firstNameInitial, lastname, false);

            PersonCollection pc;
            List<Person> personList = new List<Person>();

            // Get persons with this e-mail address
            pc = new PersonCollection();
            pc.LoadByEmail(email);
            personList.AddRange((from pcbe in pc
                                 select pcbe).ToList());

            // Get persons with this phone number
            if (!String.IsNullOrEmpty(phonehome))
            {
                phonehome = PersonPhone.FormatPhone(phonehome);
                pc = new PersonCollection();
                pc.LoadByPhone(phonehome);
                personList.AddRange((from pcbe in pc
                                     select pcbe).ToList());
            }
            if (!String.IsNullOrEmpty(phonecell))
            {
                phonecell = PersonPhone.FormatPhone(phonecell);
                pc = new PersonCollection();
                pc.LoadByPhone(phonecell);
                personList.AddRange((from pcbe in pc
                                     select pcbe).ToList());
            }

            // Get persons with this address and first initial
            Address address = new Address(street1, street2, city, state, postalcode);
            CoreAddressService cas = new CoreAddressService();
            List<int> addressIdList = cas.GetList(address.StreetLine1, address.StreetLine2, address.PostalCode);
            Person person = new Person();

            // TODO: enhance Arena with LoadByAddressIDs function to improve performance
            foreach (int addressId in addressIdList)
            {
                PersonAddressCollection pac = new PersonAddressCollection();
                pac.LoadByAddressID(addressId);

                foreach (PersonAddress pa in pac)
                {
                    person = new Person(pa.PersonID);
                    if ((person.FirstName.ToLower().StartsWith(firstNameInitial.ToLower()) || person.NickName.ToLower().StartsWith(firstNameInitial.ToLower())))
                    {
                        personList.Add(person);
                    }
                }
            }

            // Remove duplicates
            personList = (from p in personList select p).Distinct().ToList();

            // Load persons over the Match Percent Minimum threshold
            List<int> personIdList = new List<int>();
            Contracts.PersonReference personReference = new Contracts.PersonReference();
            string mapMatch = String.Empty;
            int counter = 0;

            foreach (Person p in personList)
            {
                if ((from prl in personIdList where prl == p.PersonID select prl).Count() == 0)
                {
                    counter++;
                    personReference = ConvertPersonToPersonReference(p);
                    personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch);
                    personReference.MatchMap = mapMatch;
                    personReference.IsExact = "false";
                    // If Person is greater than Match Percent Minimum then check for exact match and add to
                    if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum)
                    {
                        string domain = String.Empty;
                        personReference.IsExact = IsPersonQualifiedForExact(p, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString();
                        personReference.IsExactPrimaryEmailDomain = domain;
                        personReferenceList.Items.Add(personReference);
                        personIdList.Add(personReference.PersonId);
                    }
                }
            }

            foreach (core_person cp in persons)
            {
                if ((from prl in personIdList where prl == cp.person_id select prl).Count() == 0)
                {
                    counter++;
                    person = new Person(cp.person_id);
                    personReference = ConvertPersonToPersonReference(person);
                    personReference.IsExact = "false";
                    personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch);
                    personReference.MatchMap = mapMatch;
                    // If Person is greater than Match Percent Minimum then check for exact match
                    if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum)
                    {
                        string domain = String.Empty;
                        personReference.IsExact = IsPersonQualifiedForExact(person, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString();
                        personReference.IsExactPrimaryEmailDomain = domain;
                        personReferenceList.Items.Add(personReference);
                        personIdList.Add(personReference.PersonId);
                    }
                }
            }

            // Order filtered persons by Match Percent
            Contracts.GenericListResult<Contracts.PersonReference> personsSorted = new Contracts.GenericListResult<Contracts.PersonReference>();
            personsSorted.Items = new List<Contracts.PersonReference>();
            personsSorted.Items = (from prl in personReferenceList.Items orderby Convert.ToInt32(prl.MatchPercent) descending select prl).ToList();

            personsSorted.Max = counter;
            personsSorted.Total = personReferenceList.Items.Count();

            return personsSorted;
        }