コード例 #1
0
        private void BindData()
        {
            string contents = GetAttributeValue(AttributeKey.Contents);

            string appRoot   = ResolveRockUrl("~/");
            string themeRoot = ResolveRockUrl("~~/");

            contents = contents.Replace("~~/", themeRoot).Replace("~/", appRoot);

            var includedConnectionTypeGuids = GetAttributeValue(AttributeKey.IncludedConnectionTypes).SplitDelimitedValues().AsGuidList();
            var excludedConnectionTypeGuids = GetAttributeValue(AttributeKey.ExcludedConnectionTypes).SplitDelimitedValues().AsGuidList();

            DateTime midnightToday = RockDateTime.Today.AddDays(1);

            var rockContext        = new RockContext();
            var connectionRequests = new ConnectionRequestService(rockContext).Queryable()
                                     .Where(a => a.ConnectorPersonAlias != null && a.ConnectorPersonAlias.PersonId == CurrentPersonId)
                                     .Where(r => r.ConnectionState == ConnectionState.Active ||
                                            (r.ConnectionState == ConnectionState.FutureFollowUp && r.FollowupDate.HasValue && r.FollowupDate.Value < midnightToday));

            if (includedConnectionTypeGuids.Any())
            {
                connectionRequests = connectionRequests.Where(a => includedConnectionTypeGuids.Contains(a.ConnectionOpportunity.ConnectionType.Guid));
            }

            if (excludedConnectionTypeGuids.Any())
            {
                connectionRequests = connectionRequests.Where(a => !excludedConnectionTypeGuids.Contains(a.ConnectionOpportunity.ConnectionType.Guid));
            }

            connectionRequests = connectionRequests.OrderBy(r => r.PersonAlias.Person.LastName).ThenBy(r => r.PersonAlias.Person.NickName);

            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson, new Rock.Lava.CommonMergeFieldsOptions {
                GetLegacyGlobalMergeFields = false
            });

            mergeFields.Add("ConnectionRequests", connectionRequests.ToList());

            var lastActivityNotes = connectionRequests.Select(r => new
            {
                ConnectionRequestId = r.Id,
                LastActivity        = r.ConnectionRequestActivities.OrderByDescending(
                    a => a.CreatedDateTime).FirstOrDefault()
            }).ToDictionary(k => k.ConnectionRequestId, v => v.LastActivity);

            mergeFields.Add("LastActivityLookup", lastActivityNotes);

            Dictionary <string, object> linkedPages = new Dictionary <string, object>();

            linkedPages.Add("DetailPage", LinkedPageRoute(AttributeKey.DetailPage));
            mergeFields.Add("LinkedPages", linkedPages);

            lContents.Text = contents.ResolveMergeFields(mergeFields);
        }