Esempio n. 1
0
        /// <summary>
        /// Determine if the currently logged in person is a valid group leader for
        /// the identified person. This takes into account all Block Settings.
        /// </summary>
        /// <param name="person">The person who must be a member of a group lead by CurrentPerson.</param>
        /// <returns>true if the CurrentPerson is a valid leader of `person`.</returns>
        bool IsGroupLeaderFor(Person person)
        {
            if (CurrentPerson != null)
            {
                using (var rockContext = new RockContext())
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var groupTypeGuids     = GetAttributeValues("GroupTypes").Select(g => new Guid(g));
                    var leaderGroups       = groupMemberService
                                             .GetByPersonId(CurrentPerson.Id)
                                             .Where(gm => gm.GroupRole.IsLeader)
                                             .Where(gm => groupTypeGuids.Contains(gm.Group.GroupType.Guid));
                    var memberGroups = groupMemberService
                                       .GetByPersonId(person.Id)
                                       .Where(gm => groupTypeGuids.Contains(gm.Group.GroupType.Guid));

                    if (!GetAttributeValue("AllowEditsToCoLeaders").AsBoolean(true))
                    {
                        memberGroups = memberGroups.Where(gm => !gm.GroupRole.IsLeader);
                    }

                    return(leaderGroups
                           .Select(gm => gm.GroupId)
                           .Intersect(memberGroups.Select(gm => gm.GroupId))
                           .Any());
                }
            }

            return(false);
        }
        public static Group GetPersonsPrimaryKciGroup(this Person person, RockContext rockContext)
        {
            var groupMemberService = new GroupMemberService(rockContext);
            var cellGroupType      = GroupTypeCache.Read(SystemGuid.GroupType.CELL_GROUP.AsGuid());

            return(groupMemberService.GetByPersonId(person.Id).Select(gm => gm.Group).FirstOrDefault(g => g.GroupTypeId == cellGroupType.Id));
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the RowCommand event of the grdPersonSearchResults control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewCommandEventArgs"/> instance containing the event data.</param>
        protected void rGridPersonResults_AddExistingPerson(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                var rockContext = new RockContext();
                GroupMemberService groupMemberService = new GroupMemberService(rockContext);
                int index    = int.Parse(e.CommandArgument.ToString());
                int personId = int.Parse(rGridPersonResults.DataKeys[index].Value.ToString());

                var family = CurrentCheckInState.CheckIn.Families.Where(f => f.Selected).FirstOrDefault();
                if (family != null)
                {
                    var checkInPerson = new CheckInPerson();
                    checkInPerson.Person = new PersonService(rockContext).Get(personId).Clone(false);
                    var isPersonInFamily = family.People.Any(p => p.Person.Id == checkInPerson.Person.Id);
                    if (!isPersonInFamily)
                    {
                        if (personVisitorType.Value != "Visitor")
                        {
                            // TODO: DT: Is this right?  Not sure this is the best way to set family id
                            var groupMember = groupMemberService.GetByPersonId(personId).FirstOrDefault();
                            groupMember.GroupId = family.Group.Id;

                            rockContext.SaveChanges();

                            checkInPerson.FamilyMember = true;
                            hfSelectedPerson.Value    += personId + ",";
                        }
                        else
                        {
                            AddVisitorGroupMemberRoles(family, personId);
                            checkInPerson.FamilyMember = false;
                            hfSelectedVisitor.Value   += personId + ",";
                        }
                        checkInPerson.Selected = true;
                        family.People.Add(checkInPerson);
                        ProcessFamily();
                    }

                    mpeAddPerson.Hide();
                }
                else
                {
                    string errorMsg = "<ul><li>You have to pick a family to add this person to.</li></ul>";
                    maWarning.Show(errorMsg, Rock.Web.UI.Controls.ModalAlertType.Warning);
                }
            }
            else
            {
                mpeAddPerson.Show();
                BindPersonGrid();
            }
        }
        public static IQueryable <Group> GetGroupsLead(this Person leader, RockContext rockContext)
        {
            var groupMemberService = new GroupMemberService(rockContext);
            var cellGroupType      = GroupTypeCache.Read(SystemGuid.GroupType.CELL_GROUP.AsGuid());

            var consolidatorCoordinatorGuid = SystemGuid.GroupTypeRole.CONSOLIDATION_COORDINATOR.AsGuid();

            if (cellGroupType == null)
            {
                throw new Exception("Cannot locate KCI Group type");
            }
            return(groupMemberService
                   .GetByPersonId(leader.Id)
                   .Where(gm => gm.Group.GroupTypeId == cellGroupType.Id && (gm.GroupRole.IsLeader || gm.GroupRole.Guid == consolidatorCoordinatorGuid)).Select(gm => gm.Group).Distinct());
        }
Esempio n. 5
0
        public IQueryable <PrayerRequest> GetForGroupMembersOfPersonInGroupTypes(bool excludePerson, string groupTypeIds, int personId)
        {
            RockContext rockContext = new RockContext();

            System.DateTime now = RockDateTime.Now;

            // Turn the comma separated list of groupTypeIds into a list of strings.
            List <int> groupTypeIdsList = (groupTypeIds ?? "").Split(',').AsIntegerList();

            GroupMemberService groupMemberService = new GroupMemberService(rockContext);

            IQueryable <int> groupMemberPersonAliasList = groupMemberService.GetByPersonId(personId)                                               // Get the groups that a person is a part of
                                                          .Where(gm =>
                                                                 groupTypeIdsList.Contains(gm.Group.GroupTypeId) &&                                // Filter those groups by a set of passed in group types.
                                                                 gm.Group.IsActive == true && gm.Group.IsArchived == false                         // Also make sure the groups are active and not archived.
                                                                 )
                                                          .SelectMany(gm => gm.Group.Members)                                                      // Get the members of those groups
                                                          .Where(gm => gm.GroupMemberStatus == GroupMemberStatus.Active && gm.IsArchived == false) // Make sure that the group members are active and haven't been archived
                                                          .Select(m => m.Person.Aliases.FirstOrDefault().Id);                                      // Return the person alias ids

            // Get the prayers for the people.
            PrayerRequestService       prayerRequestService = new PrayerRequestService(rockContext);
            IQueryable <PrayerRequest> prayerRequestList    = prayerRequestService.Queryable()
                                                              .Where(pr =>
                                                                     (groupMemberPersonAliasList.Contains((int)pr.RequestedByPersonAliasId)) &&
                                                                     (pr.IsActive.HasValue && pr.IsActive.Value == true) &&
                                                                     (pr.IsPublic.HasValue && pr.IsPublic.Value == true) &&
                                                                     (pr.IsApproved.HasValue && pr.IsApproved == true) &&
                                                                     (!pr.ExpirationDate.HasValue || pr.ExpirationDate.Value > now)
                                                                     );

            // Filter out the current persons prayers if excludePerson is true
            if (excludePerson)
            {
                prayerRequestList = prayerRequestList.Where(pr => pr.RequestedByPersonAlias.PersonId != personId);
            }

            //Return this as a queryable.
            return(prayerRequestList);
        }
Esempio n. 6
0
        public static IEnumerable <int> GetCellGroupIdsInLine(Person currentPerson, RockContext rockContext)
        {
            if (currentPerson == null)
            {
                return(new List <int>());
            }

            var groupMemberService = new GroupMemberService(rockContext);
            var cellGroupType      = GroupTypeCache.Read(SystemGuid.GroupType.CELL_GROUP.AsGuid());
            IQueryable <GroupMember> currentPersonsCellGroups = null;

            var consolidatorCoordinatorGuid = SystemGuid.GroupTypeRole.CONSOLIDATION_COORDINATOR.AsGuid();

            if (cellGroupType != null)
            {
                currentPersonsCellGroups = groupMemberService
                                           .GetByPersonId(currentPerson.Id)
                                           .Where(gm => gm.Group.GroupTypeId == cellGroupType.Id && (gm.GroupRole.IsLeader || gm.GroupRole.Guid == consolidatorCoordinatorGuid)).Distinct();
            }

            if (currentPersonsCellGroups == null || !currentPersonsCellGroups.Any())
            {
                return(new List <int>());
            }

            var descendentGroups = new List <int>();

            var groupService = new GroupService(rockContext);

            foreach (var groupMember in currentPersonsCellGroups)
            {
                descendentGroups.Add(groupMember.GroupId);
                descendentGroups.AddRange(groupService.GetAllDescendents(groupMember.GroupId)
                                          .Where(g => g.GroupTypeId == cellGroupType.Id)
                                          .Select(g => g.Id));
            }

            return(descendentGroups.Distinct());
        }