Example #1
0
        public Contracts.GenericListResult <Contracts.GenericReference> GetPersonEvents(int id)
        {
            EventProfileCollection eventProfileCollection = new EventProfileCollection();

            eventProfileCollection.LoadMemberEventProfiles(Arena.Core.ArenaContext.Current.Organization.OrganizationID, id, false);
            //EventProfileCollection.RemoveInactiveProfiles();

            Contracts.GenericListResult <Contracts.GenericReference> events = new Contracts.GenericListResult <Contracts.GenericReference>();
            events.Items = new List <Contracts.GenericReference>();
            Contracts.EventMapper eventMapper = new Contracts.EventMapper();
            foreach (EventProfile eProfile in eventProfileCollection)
            {
                if (eProfile.DisplayAttendedOnly)
                {
                    if (new Arena.DataLayer.Core.OccurrenceData().GetProfileAttendance(eProfile.ProfileID, id, Arena.Core.ArenaContext.Current.Organization.OrganizationID) > 0)
                    {
                        events.Items.Add(new Contracts.GenericReference(eProfile));
                    }
                }
                else
                {
                    events.Items.Add(new Contracts.GenericReference(eProfile));
                }
            }
            events.Max   = events.Total = events.Items.Count;
            events.Start = 0;

            return(events);
        }
Example #2
0
        public Contracts.GenericListResult <int> GetPersonPreviousIds(int id)
        {
            List <int> previousIds = Arena.Custom.SECC.OAuth.PersonMerges.GetOldPersonIds(id);

            Contracts.GenericListResult <int> list = new Contracts.GenericListResult <int>();
            list.Items = previousIds;
            list.Max   = list.Total = previousIds.Count;
            list.Start = 0;

            return(list);
        }
Example #3
0
        public Contracts.GenericListResult <Contracts.SmallGroup> GetPersonSmallGroupLeadership(int id, int clusterTypeId, int start, int max)
        {
            Contracts.GenericListResult <Contracts.SmallGroup> list = new Contracts.GenericListResult <Contracts.SmallGroup>();
            list.Items = new List <Contracts.SmallGroup>();
            list.Start = start;


            // Instantiate the mapper
            Contracts.SmallGroupMapper sgm = new Contracts.SmallGroupMapper();

            Arena.Custom.SECC.Data.SmallGroup.GroupCollection gc = new Arena.Custom.SECC.Data.SmallGroup.GroupCollection();
            gc.LoadByLeaderPersonID(ArenaContext.Current.Person.PersonID);

            foreach (Arena.SmallGroup.Group g in gc)
            {
                if (clusterTypeId > 0 && g.ClusterTypeID != clusterTypeId)
                {
                    continue;
                }

                // Make sure they have group cluster info if they aren't querying for themselves.
                if (ArenaContext.Current.Person.PersonID != id)
                {
                    if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, g.GroupClusterID, OperationType.View) == false)
                    {
                        continue;
                    }
                }

                // Make sure this person is an active member of the group
                bool active = true;
                foreach (Arena.SmallGroup.GroupMember gm in g.Members)
                {
                    if (!gm.Active && gm.PersonID == ArenaContext.Current.Person.PersonID)
                    {
                        active = false;
                    }
                }
                if (!active)
                {
                    continue;
                }

                if (list.Total >= start && (list.Items.Count < max || max <= 0))
                {
                    list.Items.Add(sgm.FromArena(g));
                }
            }
            list.Max = list.Total = list.Items.Count;

            return(list);
        }
Example #4
0
        public Contracts.GenericListResult<Contracts.ProfileMember> GetPersonProfileMembership(int id, int type, string inactive, int start, int max)
        {
            Contracts.GenericListResult<Contracts.ProfileMember> list = new Contracts.GenericListResult<Contracts.ProfileMember>();
            ProfileCollection pmc = new ProfileCollection();
            bool activeOnly = true;

            //
            // Check if they want to include inactive records.
            //
            try
            {
                if (Convert.ToInt32(inactive) == 1)
                    activeOnly = false;
            }
            catch { }

            //
            // Check general.
            //
            if (type == (int)Enums.ProfileType.Ministry && RestApi.PersonFieldOperationAllowed(ArenaContext.Current.Person.PersonID, PersonFields.Activity_Ministry_Tags, OperationType.View) == false)
                throw new Exception("Access denied");
            else if (type == (int)Enums.ProfileType.Serving && RestApi.PersonFieldOperationAllowed(ArenaContext.Current.Person.PersonID, PersonFields.Activity_Serving_Tags, OperationType.View) == false)
                throw new Exception("Access denied");
            else if (type != (int)Enums.ProfileType.Personal && type != (int)Enums.ProfileType.Ministry && type != (int)Enums.ProfileType.Serving)
                throw new Exception("Access denied");

            //
            // If they are requesting membership in their own personal profiles
            // then retrieve those, otherwise retrieve the general profile
            // information.
            //
            if (type == (int)Enums.ProfileType.Personal)
                pmc.LoadMemberPrivateProfiles(RestApi.DefaultOrganizationID(), ArenaContext.Current.Person.PersonID, id, activeOnly);
            else
                pmc.LoadMemberProfiles(RestApi.DefaultOrganizationID(), (Enums.ProfileType)type, id, activeOnly);

            list.Items = new List<Contracts.ProfileMember>();
            list.Start = start;
            list.Max = max;
            foreach (Profile p in pmc)
            {
                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, p.ProfileID, OperationType.View) == false)
                    continue;

                if (list.Total >= start && list.Items.Count < max)
                    list.Items.Add(new Contracts.ProfileMember(new ProfileMember(p.ProfileID, id)));
                list.Total += 1;
            }

            return list;
        }
        public Contracts.GenericListResult<Contracts.GenericReference> GetSmallGroupCategories()
        {
            Contracts.GenericListResult<Contracts.GenericReference> list = new Contracts.GenericListResult<Contracts.GenericReference>();
            CategoryCollection categories = new CategoryCollection();

            list.Items = new List<Contracts.GenericReference>();
            list.Total = categories.Count;
            list.Max = list.Total;
            list.Start = 0;
            foreach (Category category in categories)
            {
                list.Items.Add(new Contracts.GenericReference(category));
            }

            return list;
        }
Example #6
0
        public Contracts.GenericListResult <Contracts.SmallGroupMember> GetSmallGroupMembers(int groupID, int start, int max)
        {
            Contracts.GenericListResult <Contracts.SmallGroupMember> list = new Contracts.GenericListResult <Contracts.SmallGroupMember>();
            Contracts.SmallGroupMemberMapper mapper = new Contracts.SmallGroupMemberMapper();
            Group       group  = new Group(groupID);
            GroupMember leader = new GroupMember(groupID, group.Leader);

            leader.Role = new Lookup(new Guid("029B270C-7B7A-499F-8006-CC3211C91E95"));
            group.Members.Add(leader);

            Boolean accessDenied = false;

            // If this person isn't the outright leader and they don't have view access
            if (group.Leader.PersonID != ArenaContext.Current.Person.PersonID &&
                RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, group.GroupClusterID, OperationType.View) == false)
            {
                accessDenied = true;

                // Do a deeper dive into each member of the group
                foreach (GroupMember gm in group.Members)
                {
                    if (gm.Active && gm.Role.Value == "Leader")
                    {
                        accessDenied = false;
                        break;
                    }
                }
            }
            if (accessDenied)
            {
                throw new Exception("Access denied.");
            }

            list.Start = start;
            list.Max   = max;
            list.Total = group.Members.Count;
            list.Items = new List <Contracts.SmallGroupMember>();

            int i;

            for (i = start; i < group.Members.Count && (max <= 0 || i < (start + max)); i++)
            {
                list.Items.Add(mapper.FromArena(group.Members[i]));
            }

            return(list);
        }
Example #7
0
        public Contracts.GenericListResult <Contracts.FamilyMember> GetPersonFamilyMembers(int id)
        {
            Contracts.GenericListResult <Contracts.FamilyMember> list = new Contracts.GenericListResult <Contracts.FamilyMember>();
            Contracts.FamilyMemberMapper mapper = new Contracts.FamilyMemberMapper();

            var person = new Arena.Core.Person(id);

            list.Items = new List <Contracts.FamilyMember>();
            list.Max   = list.Total = person.Family().FamilyMembers.Count;
            list.Start = 0;
            foreach (FamilyMember member in person.Family().FamilyMembers)
            {
                list.Items.Add(mapper.FromArena(member));
            }

            return(list);
        }
        public Contracts.GenericListResult<Contracts.SmallGroupMember> GetSmallGroupMembers(int groupID, int start, int max)
        {
            Contracts.GenericListResult<Contracts.SmallGroupMember> list = new Contracts.GenericListResult<Contracts.SmallGroupMember>();
            Contracts.SmallGroupMemberMapper mapper = new Contracts.SmallGroupMemberMapper();
            Group group = new Group(groupID);
            GroupMember leader = new GroupMember(groupID, group.Leader);
            leader.Role = new Lookup(new Guid("029B270C-7B7A-499F-8006-CC3211C91E95"));
            group.Members.Add(leader);

            Boolean accessDenied = false;
            // If this person isn't the outright leader and they don't have view access
            if (group.Leader.PersonID != ArenaContext.Current.Person.PersonID &&
                RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, group.GroupClusterID, OperationType.View) == false) {

                accessDenied = true;

                // Do a deeper dive into each member of the group
                foreach(GroupMember gm in group.Members) {
                    if (gm.Active && gm.Role.Value == "Leader")
                    {
                        accessDenied = false;
                        break;
                    }
                }
            }
            if (accessDenied) {
                throw new Exception("Access denied.");
            }

            list.Start = start;
            list.Max = max;
            list.Total = group.Members.Count;
            list.Items = new List<Contracts.SmallGroupMember>();

            int i;
            for (i = start; i < group.Members.Count && (max <= 0 || i < (start + max)); i++)
            {
                list.Items.Add(mapper.FromArena(group.Members[i]));
            }

            return list;
        }
Example #9
0
        public Contracts.GenericListResult <Contracts.SmallGroupOccurrence> GetSmallGroupOccurences(int groupId, String start, String end)
        {
            var list = new Contracts.GenericListResult <Contracts.SmallGroupOccurrence>();

            list.Items = new List <Contracts.SmallGroupOccurrence>();

            Contracts.SmallGroupOccurrenceMapper mapper = new Contracts.SmallGroupOccurrenceMapper();
            Group group = new Group(groupId);

            foreach (GroupOccurrence occurrence in group.Occurrences)
            {
                if (occurrence.StartTime >= DateTime.ParseExact(start, "yyyyMMddHHmmss", new CultureInfo("en-us")) &&
                    occurrence.EndTime <= DateTime.ParseExact(end, "yyyyMMddHHmmss", new CultureInfo("en-us")))
                {
                    list.Items.Add(mapper.FromArena(occurrence));
                }
            }
            list.Start = 0;
            list.Total = list.Max = list.Items.Count;

            return(list);
        }
        public Contracts.GenericListResult<Contracts.SmallGroupOccurrence> GetSmallGroupOccurences(int groupId, String start, String end)
        {
            var list = new Contracts.GenericListResult<Contracts.SmallGroupOccurrence>();
            list.Items = new List<Contracts.SmallGroupOccurrence>();

            Contracts.SmallGroupOccurrenceMapper mapper = new Contracts.SmallGroupOccurrenceMapper();
            Group group = new Group(groupId);

            foreach (GroupOccurrence occurrence in group.Occurrences)
            {
                if ( occurrence.StartTime >= DateTime.ParseExact( start, "yyyyMMddHHmmss", new CultureInfo( "en-us" ) )
                    && occurrence.EndTime <= DateTime.ParseExact( end, "yyyyMMddHHmmss", new CultureInfo( "en-us" ) ) )
                {
                    list.Items.Add( mapper.FromArena( occurrence ) );
                }
            }
            list.Start = 0;
            list.Total = list.Max = list.Items.Count;

            return list;
        }
        public Contracts.GenericListResult<Contracts.GenericReference> GetSmallGroups(int clusterID, int start, int max)
        {
            Contracts.GenericListResult<Contracts.GenericReference> list = new Contracts.GenericListResult<Contracts.GenericReference>();
            GroupCollection groups = new GroupCollection(clusterID);
            int i;

            if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, clusterID, OperationType.View) == false)
                throw new Exception("Access denied.");

            list.Start = start;
            list.Max = max;
            list.Total = groups.Count;
            list.Items = new List<Contracts.GenericReference>();
            for (i = start; i < groups.Count && (max <= 0 || i < (start + max)); i++)
            {
                list.Items.Add(new Contracts.GenericReference(groups[i]));
            }

            return list;
        }
Example #12
0
        public Contracts.GenericListResult<Contracts.ProfileMember> GetProfileMembers(int profileID, String statusID, int start, int max)
        {
            Contracts.GenericListResult<Contracts.ProfileMember> list = new Contracts.GenericListResult<Contracts.ProfileMember>();
            Profile profile = new Profile(profileID);
            int i, nStatusID;

            if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profile.ProfileID, OperationType.View) == false)
                throw new Exception("Access denied.");

            try
            {
                nStatusID = Convert.ToInt32(statusID);
            }
            catch
            {
                nStatusID = -1;
            }

            profile.LoadMemberArray();
            list.Start = start;
            list.Max = max;
            list.Total = 0;
            list.Items = new List<Contracts.ProfileMember>();

            for (i = 0; i < profile.Members.Count; i++)
            {
                if (nStatusID != -1 && profile.Members[i].Status.LookupID != nStatusID)
                    continue;

                if (list.Total >= start && (max <= 0 ? true : list.Items.Count < max))
                    list.Items.Add(new Contracts.ProfileMember(profile.Members[i]));
                list.Total += 1;
            }

            return list;
        }
Example #13
0
        public Contracts.GenericListResult<Contracts.PersonRelationship> GetPersonRelationships(int id)
        {
            Contracts.GenericListResult<Contracts.PersonRelationship> list = new Contracts.GenericListResult<Contracts.PersonRelationship>();
            Contracts.PersonRelationshipMapper mapper = new Contracts.PersonRelationshipMapper();
            RelationshipCollection relationships = new RelationshipCollection(id);

            list.Items = new List<Contracts.PersonRelationship>();
            list.Total = relationships.Count;
            list.Max = list.Total;
            list.Start = 0;
            foreach (Relationship relationship in relationships)
            {
                list.Items.Add(mapper.FromArena(relationship));
            }

            return list;
        }
Example #14
0
        public Contracts.GenericListResult<Contracts.SmallGroupMember> GetPersonSmallGroupMembership(int id, int start, int max)
        {
            Contracts.GenericListResult<Contracts.SmallGroupMember> list = new Contracts.GenericListResult<Contracts.SmallGroupMember>();
            Contracts.SmallGroupMemberMapper mapper = new Contracts.SmallGroupMemberMapper();
            Contracts.SmallGroupMember member;
            CategoryCollection cc = new CategoryCollection();
            GroupCollection gc = new GroupCollection();
            GroupMember gm;

            //
            // If they are requesting membership for a person, get the list
            // of groups this person is a member of. Does not return groups
            // this person is a leader of.
            //
            list.Items = new List<Contracts.SmallGroupMember>();
            list.Start = start;
            list.Max = max;
            foreach (Category c in cc)
            {
                gc = new GroupCollection();
                gc.LoadByPersonID(id, c.CategoryID);

                foreach (Group g in gc)
                {
                    if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, g.GroupClusterID, OperationType.View) == false)
                        continue;

                    if (list.Total >= start && list.Items.Count < max)
                    {
                        gm = new GroupMember(g.GroupID, id);
                        member = mapper.FromArena(new GroupMember(g.GroupID, id));
                        if (member.Group.ID == -1)
                            continue;

                        list.Items.Add(mapper.FromArena(gm));
                    }

                    list.Total += 1;
                }
            }

            return list;
        }
Example #15
0
        public Contracts.GenericListResult<Contracts.GenericReference> GetPersonSmallGroupLeadership(int id, int start, int max)
        {
            Contracts.GenericListResult<Contracts.GenericReference> list = new Contracts.GenericListResult<Contracts.GenericReference>();
            GroupCollection gc = new GroupCollection();

            //
            // If they are requesting membership for a person, get the list
            // of groups this person is a member of. Does not return groups
            // this person is a leader of.
            //
            list.Items = new List<Contracts.GenericReference>();
            gc.LoadByLeaderPersonID(id);
            list.Start = start;
            list.Max = max;
            foreach (Group g in gc)
            {
                if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, g.GroupClusterID, OperationType.View) == false)
                    continue;

                if (list.Total >= start && list.Items.Count < max)
                    list.Items.Add(new Contracts.GenericReference(g));
            }

            return list;
        }
Example #16
0
        public Object GetProfileList(String profileID, String profileType, int start, int max, String fields)
        {
            ProfileCollection profiles = null;
            Contracts.ProfileMapper mapper = null;
            Contracts.GenericListResult<Contracts.Profile> listP = new Contracts.GenericListResult<Contracts.Profile>();
            Contracts.GenericListResult<Contracts.GenericReference> listR = new Contracts.GenericListResult<Contracts.GenericReference>();
            int i;

            if (profileType != null)
            {
                profiles = new ProfileCollection();
                profiles.LoadChildProfiles(-1, RestApi.DefaultOrganizationID(), (Arena.Enums.ProfileType)Convert.ToInt32(profileType), ArenaContext.Current.Person.PersonID);
            }
            else if (profileID != null)
            {
                Profile profile;

                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(profileID), OperationType.View) == false)
                    throw new Exception("Access denied.");

                profile = new Profile(Convert.ToInt32(profileID));
                profiles = profile.ChildProfiles;
            }
            else
                throw new Exception("Required parameters not provided.");

            //
            // Sort the list of profiles and determine if we are going to
            // be returning references or full objects.
            //
            profiles.Sort(delegate(Profile p1, Profile p2) { return p1.Name.CompareTo(p2.Name); });
            mapper = (string.IsNullOrEmpty(fields) ? null : new Contracts.ProfileMapper(new List<string>(fields.Split(','))));

            //
            // Prepare the appropraite list object.
            //
            if (mapper != null)
            {
                listP.Start = start;
                listP.Max = max;
                listP.Total = 0;
                listP.Items = new List<Contracts.Profile>();
            }
            else
            {
                listR.Start = start;
                listR.Max = max;
                listR.Total = 0;
                listR.Items = new List<Contracts.GenericReference>();
            }
            for (i = 0; i < profiles.Count; i++)
            {
                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profiles[i].ProfileID, OperationType.View) == false)
                    continue;

                if (mapper != null)
                {
                    if (listP.Total >= start && (max <= 0 ? true : listP.Items.Count < max))
                        listP.Items.Add(mapper.FromArena(profiles[i]));
                    listP.Total += 1;
                }
                else
                {
                    if (listR.Total >= start && (max <= 0 ? true : listR.Items.Count < max))
                       listR.Items.Add(new Contracts.GenericReference(profiles[i]));
                    listR.Total += 1;
                }
            }

            return (mapper != null ? (Object)listP : (Object)listR);
        }
        public Contracts.GenericListResult<Contracts.GenericReference> GetSmallGroupClusters(String categoryID, String clusterID, int start, int max)
        {
            GroupClusterCollection clusters;
            Contracts.GenericListResult<Contracts.GenericReference> list = new Contracts.GenericListResult<Contracts.GenericReference>();
            int i;

            if (categoryID != null)
            {
                clusters = new GroupClusterCollection(Convert.ToInt32(categoryID), Convert.ToInt32(ConfigurationManager.AppSettings["Organization"]));
            }
            else if (clusterID != null)
            {
                if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(clusterID), OperationType.View) == false)
                    throw new Exception("Access denied.");

                clusters = new GroupClusterCollection(Convert.ToInt32(clusterID));
            }
            else
                throw new Exception("Required parameters not provided.");

            list.Start = start;
            list.Max = max;
            list.Total = clusters.Count;
            list.Items = new List<Contracts.GenericReference>();
            clusters.Sort(delegate(GroupCluster gc1, GroupCluster gc2) { return gc1.Name.CompareTo(gc2.Name); });
            for (i = start; i < clusters.Count && (max <= 0 || i < (start + max)); i++)
            {
                if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, clusters[i].GroupClusterID, OperationType.View) == true)
                {
                    list.Items.Add(new Contracts.GenericReference(clusters[i]));
                }
            }

            return list;
        }
        public Contracts.GenericListResult<Contracts.SmallGroupMember> GetSmallGroupMembers(int groupID, int start, int max)
        {
            Contracts.GenericListResult<Contracts.SmallGroupMember> list = new Contracts.GenericListResult<Contracts.SmallGroupMember>();
            Contracts.SmallGroupMemberMapper mapper = new Contracts.SmallGroupMemberMapper();
            Group group = new Group(groupID);
            int i;

            if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, group.GroupClusterID, OperationType.View) == false)
                throw new Exception("Access denied.");

            group.LoadMemberArray();
            list.Start = start;
            list.Max = max;
            list.Total = group.Members.Count;
            list.Items = new List<Contracts.SmallGroupMember>();

            for (i = start; i < group.Members.Count && (max <= 0 || i < (start + max)); i++)
            {
                list.Items.Add(mapper.FromArena(group.Members[i]));
            }

            return list;
        }
        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;
        }
Example #20
0
        public Contracts.GenericListResult<Contracts.ProfileMemberActivity> GetProfileMemberActivity(int profileID, int personID, int start, int max)
        {
            Contracts.GenericListResult<Contracts.ProfileMemberActivity> list = new Contracts.GenericListResult<Contracts.ProfileMemberActivity>();
            Profile profile = new Profile(profileID);
            DataTable dt;
            int i;

            //
            // Check if the profile exists.
            //
            if (profile.ProfileID == -1)
                throw new Arena.Services.Exceptions.ResourceNotFoundException("Invalid profile ID");

            //
            // Check if the user has access to work with the profile.
            //
            if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profile.ProfileID, OperationType.View) == false)
                throw new Exception("Access denied.");

            dt = new ProfileMemberActivityData().GetProfileMemberActivityDetails_DT(RestApi.DefaultOrganizationID(), profile.ProfileType, profile.Owner.PersonID, personID);
            list.Start = start;
            list.Max = max;
            list.Items = new List<Contracts.ProfileMemberActivity>();
            for (i = 0; i < dt.Rows.Count; i++)
            {
                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(dt.Rows[i]["profile_id"]), OperationType.View) == false)
                    continue;

                if (list.Total >= start && (max <= 0 ? true : list.Items.Count < max))
                    list.Items.Add(new Contracts.ProfileMemberActivity(dt.Rows[i]));
                list.Total += 1;
            }

            return list;
        }