Пример #1
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            if (Person != null && Person.Id > 0)
            {
                if (ownerRoleGuid != Guid.Empty)
                {
                    using (var rockContext = new RockContext())
                    {
                        var memberService = new GroupMemberService(rockContext);
                        var group         = memberService.Queryable(true)
                                            .Where(m =>
                                                   m.PersonId == Person.Id &&
                                                   m.GroupRole.Guid == ownerRoleGuid)
                                            .Select(m => m.Group)
                                            .FirstOrDefault();

                        if (group == null && GetAttributeValue("CreateGroup").AsBoolean())
                        {
                            var role = new GroupTypeRoleService(rockContext).Get(ownerRoleGuid);
                            if (role != null && role.GroupTypeId.HasValue)
                            {
                                var groupService = new GroupService(rockContext);
                                group             = new Group();
                                group.Name        = role.GroupType.Name;
                                group.GroupTypeId = role.GroupTypeId.Value;
                                groupService.Add(group);
                                rockContext.SaveChanges();

                                var groupMember = new GroupMember();
                                groupMember.PersonId    = Person.Id;
                                groupMember.GroupRoleId = role.Id;
                                groupMember.GroupId     = group.Id;
                                group.Members.Add(groupMember);
                                rockContext.SaveChanges();

                                group = groupService.Get(group.Id);
                            }
                        }

                        if (group != null)
                        {
                            lGroupName.Text        = group.Name.Pluralize();
                            lGroupTypeIcon.Text    = string.Format("<i class='{0}'></i>", group.GroupType.IconCssClass);
                            lGroupTypeIcon.Visible = !string.IsNullOrWhiteSpace(group.GroupType.IconCssClass);
                            phEditActions.Visible  = group.IsAuthorized(Authorization.EDIT, CurrentPerson);

                            if (group.IsAuthorized(Authorization.VIEW, CurrentPerson))
                            {
                                int?maxRelationshipsToDisplay = this.GetAttributeValue("MaxRelationshipsToDisplay").AsIntegerOrNull();

                                IQueryable <GroupMember> qryGroupMembers = new GroupMemberService(rockContext).GetByGroupId(group.Id, true)
                                                                           .Where(m => m.PersonId != Person.Id)
                                                                           .OrderBy(m => m.Person.LastName)
                                                                           .ThenBy(m => m.Person.FirstName);

                                if (maxRelationshipsToDisplay.HasValue)
                                {
                                    qryGroupMembers = qryGroupMembers.Take(maxRelationshipsToDisplay.Value);
                                }

                                rGroupMembers.DataSource = qryGroupMembers.ToList();
                                rGroupMembers.DataBind();
                            }
                            else
                            {
                                lAccessWarning.Text = string.Format("<div class='alert alert-info'>You do not have security rights to view {0}.", group.Name.Pluralize());
                            }
                        }
                        else
                        {
                            lGroupName.Text = this.BlockCache.Name;
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            ShowRole = GetAttributeValue("ShowRole").AsBoolean();

            if (person != null && person.Id > 0)
            {
                if (ownerRoleGuid != Guid.Empty)
                {
                    using (var rockContext = new RockContext())
                    {
                        var memberService = new GroupMemberService(rockContext);
                        var group         = memberService.Queryable(true)
                                            .Where(m =>
                                                   m.PersonId == person.Id &&
                                                   m.GroupRole.Guid == ownerRoleGuid)
                                            .Select(m => m.Group)
                                            .FirstOrDefault();

                        if (group != null)
                        {
                            lGroupName.Text        = group.Name.Pluralize();
                            lGroupTypeIcon.Text    = string.Format("<i class='{0}'></i>", group.GroupType.IconCssClass);
                            lGroupTypeIcon.Visible = !string.IsNullOrWhiteSpace(group.GroupType.IconCssClass);

                            if (group.IsAuthorized(Authorization.VIEW, CurrentPerson))
                            {
                                int?maxRelationshipsToDisplay = this.GetAttributeValue("MaxRelationshipsToDisplay").AsIntegerOrNull();

                                var roles = new List <int>();
                                if (canCheckInOnly)
                                {
                                    foreach (var role in new GroupTypeRoleService(rockContext)
                                             .Queryable().AsNoTracking()
                                             .Where(r => r.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS))))
                                    {
                                        role.LoadAttributes(rockContext);
                                        if (role.Attributes.ContainsKey("CanCheckin"))
                                        {
                                            bool canCheckIn = false;
                                            if (bool.TryParse(role.GetAttributeValue("CanCheckin"), out canCheckIn) && canCheckIn)
                                            {
                                                roles.Add(role.Id);
                                            }
                                        }

                                        if (role.Attributes.ContainsKey("InverseRelationship"))
                                        {
                                            var inverseRoleGuid = role.GetAttributeValue("InverseRelationship").AsGuidOrNull();
                                            if (inverseRoleGuid != null)
                                            {
                                                var groupTypeRole = new GroupTypeRoleService(rockContext)
                                                                    .Queryable().AsNoTracking()
                                                                    .FirstOrDefault(r => r.Guid.Equals(( Guid )inverseRoleGuid));
                                                if (groupTypeRole != null)
                                                {
                                                    groupTypeRole.LoadAttributes(rockContext);
                                                    if (groupTypeRole.Attributes.ContainsKey("CanCheckin"))
                                                    {
                                                        bool canCheckIn = false;
                                                        if (bool.TryParse(groupTypeRole.GetAttributeValue("CanCheckin"), out canCheckIn) && canCheckIn)
                                                        {
                                                            roles.Add(role.Id);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var role in new GroupTypeRoleService(rockContext)
                                             .Queryable().AsNoTracking()
                                             .Where(r => r.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS))))
                                    {
                                        roles.Add(role.Id);
                                    }
                                }

                                IQueryable <GroupMember> qryGroupMembers = new GroupMemberService(rockContext).GetByGroupId(group.Id, true)
                                                                           .Where(m => m.PersonId != person.Id)
                                                                           .Where(m => roles.Contains(m.GroupRoleId))
                                                                           .OrderBy(m => m.Person.LastName)
                                                                           .ThenBy(m => m.Person.FirstName);

                                if (maxRelationshipsToDisplay.HasValue)
                                {
                                    qryGroupMembers = qryGroupMembers.Take(maxRelationshipsToDisplay.Value);
                                }

                                rGroupMembers.ItemDataBound += rptrMembers_ItemDataBound;
                                rGroupMembers.DataSource     = qryGroupMembers.ToList();
                                rGroupMembers.DataBind();
                            }
                            else
                            {
                                lAccessWarning.Text = string.Format("<div class='alert alert-info'>You do not have security rights to view {0}.", group.Name.Pluralize());
                            }
                        }
                    }
                }
            }
        }