コード例 #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            if (_isFamilyGroupType)
            {
                var adults = GroupMembers.Where(m => m.GroupRoleId != _childRoleId).ToList();
                ddlMaritalStatus.Visible = adults.Any();
            }

            base.OnPreRender(e);
        }
コード例 #2
0
        void lbRemoveMember_Click(object sender, EventArgs e)
        {
            Guid personGuid  = ((LinkButton)sender).ID.Substring(15).Replace("_", "-").AsGuid();
            var  groupMember = GroupMembers.Where(f => f.Person.Guid.Equals(personGuid)).FirstOrDefault();

            if (groupMember != null)
            {
                GroupMembers.Remove(groupMember);
                Duplicates.Remove(personGuid);
                if (!GroupMembers.Any())
                {
                    AddGroupMember();
                    CurrentPageIndex = 0;
                }
                CreateControls(true);
            }
        }
コード例 #3
0
        public bool FindDuplicates()
        {
            Duplicates = new Dictionary <Guid, List <Person> >();

            var rockContext     = new RockContext();
            var locationService = new LocationService(rockContext);
            var groupService    = new GroupService(rockContext);
            var personService   = new PersonService(rockContext);

            // Find any other group members (any group) that have same location
            var othersAtAddress = new List <int>();

            string locationKey = GetLocationKey();

            if (!string.IsNullOrWhiteSpace(locationKey) && _verifiedLocations.ContainsKey(locationKey))
            {
                int?locationId = _verifiedLocations[locationKey];
                if (locationId.HasValue)
                {
                    var location = locationService.Get(locationId.Value);
                    if (location != null)
                    {
                        othersAtAddress = groupService
                                          .Queryable().AsNoTracking()
                                          .Where(g =>
                                                 g.GroupTypeId == _locationType.Id &&
                                                 g.GroupLocations.Any(l => l.LocationId == location.Id))
                                          .SelectMany(g => g.Members)
                                          .Select(m => m.PersonId)
                                          .ToList();
                    }
                }
            }

            foreach (var person in GroupMembers
                     .Where(m =>
                            m.Person != null &&
                            m.Person.FirstName != "")
                     .Select(m => m.Person))
            {
                bool otherCriteria = false;
                var  personQry     = personService
                                     .Queryable().AsNoTracking()
                                     .Where(p =>
                                            p.FirstName == person.FirstName ||
                                            p.NickName == person.FirstName);

                if (othersAtAddress.Any())
                {
                    personQry = personQry
                                .Where(p => othersAtAddress.Contains(p.Id));
                }

                if (person.BirthDate.HasValue)
                {
                    otherCriteria = true;
                    personQry     = personQry
                                    .Where(p =>
                                           p.BirthDate.HasValue &&
                                           p.BirthDate.Value == person.BirthDate.Value);
                }

                if (_homePhone != null)
                {
                    var homePhoneNumber = person.PhoneNumbers.Where(p => p.NumberTypeValueId == _homePhone.Id).FirstOrDefault();
                    if (homePhoneNumber != null)
                    {
                        otherCriteria = true;
                        personQry     = personQry
                                        .Where(p =>
                                               p.PhoneNumbers.Any(n =>
                                                                  n.NumberTypeValueId == _homePhone.Id &&
                                                                  n.Number == homePhoneNumber.Number));
                    }
                }

                if (_cellPhone != null)
                {
                    var cellPhoneNumber = person.PhoneNumbers.Where(p => p.NumberTypeValueId == _cellPhone.Id).FirstOrDefault();
                    if (cellPhoneNumber != null)
                    {
                        otherCriteria = true;
                        personQry     = personQry
                                        .Where(p =>
                                               p.PhoneNumbers.Any(n =>
                                                                  n.NumberTypeValueId == _cellPhone.Id &&
                                                                  n.Number == cellPhoneNumber.Number));
                    }
                }

                if (!string.IsNullOrWhiteSpace(person.Email))
                {
                    otherCriteria = true;
                    personQry     = personQry
                                    .Where(p => p.Email == person.Email);
                }

                var dups = new List <Person>();
                if (otherCriteria)
                {
                    // If a birthday, email, phone, or address was entered, find anyone with same info and same first name
                    dups = personQry.ToList();
                }
                else
                {
                    // otherwise find people with same first and last name
                    dups = personQry
                           .Where(p => p.LastName == person.LastName)
                           .ToList();
                }
                if (dups.Any())
                {
                    Duplicates.Add(person.Guid, dups);
                }
            }

            return(Duplicates.Any());
        }