/// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            //// Spouse is determined if all these conditions are met
            //// 1) Adult in the same family as Person (GroupType = Family, GroupRole = Adult, and in same Group)
            //// 2) Opposite Gender as Person
            //// 3) Both Persons are Married

            Guid adultGuid             = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
            Guid marriedGuid           = Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid();
            int  marriedDefinedValueId = DefinedValueCache.Read(marriedGuid).Id;
            Guid familyGuid            = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

            var familyGroupMembers = new GroupMemberService(context).Queryable()
                                     .Where(m => m.Group.GroupType.Guid == familyGuid);

            var personSpouseQuery = new PersonService(context).Queryable()
                                    .Select(p => familyGroupMembers.Where(s => s.PersonId == p.Id && s.Person.MaritalStatusValueId == marriedDefinedValueId && s.GroupRole.Guid == adultGuid)
                                            .SelectMany(m => m.Group.Members)
                                            .Where(fm => fm.PersonId != p.Id)
                                            .Where(m => m.GroupRole.Guid == adultGuid)
                                            .Where(m => m.Person.Gender != p.Gender)
                                            .Where(m => m.Person.MaritalStatusValueId == marriedDefinedValueId)
                                            .Select(m => m.Person.FirstName).FirstOrDefault());

            var selectSpouseExpression = SelectExpressionExtractor.Extract <Rock.Model.Person>(personSpouseQuery, entityIdProperty, "p");

            return(selectSpouseExpression);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var kciSmallGroupGuid = SystemGuid.GroupType.CELL_GROUP.AsGuid();
            // TODO Change
            var attributeId = 1;

            var leaderAttributes = new AttributeValueService(context)
                                   .Queryable()
                                   .Where(av => av.AttributeId == attributeId);

            var personService = new PersonService(context).Queryable();

            var lineLeaderQuery = new PersonService(context)
                                  .Queryable()
                                  .Select(p => leaderAttributes
                                          .Where(a => a.EntityId == p.Id)
                                          .Select(a => personService
                                                  .AsQueryable()
                                                  .FirstOrDefault(q => q.Id == a.ValueAsPersonId)
                                                  .FullName
                                                  )
                                          );

            var selectLineLeaderExpression = SelectExpressionExtractor.Extract(lineLeaderQuery, entityIdProperty, "p");

            return(selectLineLeaderExpression);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            Guid adultGuid  = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
            Guid childGuid  = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid();
            Guid familyGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();
            Guid?phoneNumberTypeValueGuid = selection.AsGuidOrNull();

            if (!phoneNumberTypeValueGuid.HasValue)
            {
                phoneNumberTypeValueGuid = Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME.AsGuid();
            }

            int phoneNumberTypeValueId = DefinedValueCache.Read(phoneNumberTypeValueGuid.Value).Id;

            var familyGroupMembers = new GroupMemberService(context).Queryable()
                                     .Where(m => m.Group.GroupType.Guid == familyGuid);

            // this returns Enumerable of PhoneNumber for Parents per row. The Grid then uses ListDelimiterField to convert the list into Parent's Phone Numbers
            var personParentsPhoneQuery = new PersonService(context).Queryable()
                                          .Select(p => familyGroupMembers.Where(s => s.PersonId == p.Id && s.GroupRole.Guid == childGuid)
                                                  .SelectMany(m => m.Group.Members)
                                                  .Where(m => m.GroupRole.Guid == adultGuid)
                                                  .Select(m => m.Person)
                                                  .Where(m => m.PhoneNumbers.Count(t => t.NumberTypeValueId == phoneNumberTypeValueId) != 0)
                                                  .Select(m => m.PhoneNumbers.FirstOrDefault(t => t.NumberTypeValueId == phoneNumberTypeValueId)).AsEnumerable());

            var selectNumbersExpression = SelectExpressionExtractor.Extract(personParentsPhoneQuery, entityIdProperty, "p");

            return(selectNumbersExpression);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override System.Linq.Expressions.Expression GetExpression(Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection)
        {
            bool showAsLink   = this.GetAttributeValueFromSelection("ShowAsLink", selection).AsBooleanOrNull() ?? false;
            int  displayOrder = this.GetAttributeValueFromSelection("DisplayOrder", selection).AsIntegerOrNull() ?? 0;
            var  personQry    = new PersonService(context).Queryable();
            IQueryable <string> personLinkQuery;

            if (showAsLink)
            {
                // return string in format: <a href='/person/{personId}'>LastName, NickName</a>
                // prepend it with <!--LastName, NickName--> so that Sorting Works as expected
                if (displayOrder == 0)
                {
                    personLinkQuery = personQry.Select(p => "<!--" + p.NickName + " " + p.LastName + "--><a href='/person/" + p.Id.ToString() + "'>" + p.NickName + " " + p.LastName + "</a>");
                }
                else
                {
                    personLinkQuery = personQry.Select(p => "<!--" + p.LastName + ", " + p.NickName + "--><a href='/person/" + p.Id.ToString() + "'>" + p.LastName + ", " + p.NickName + "</a>");
                }
            }
            else
            {
                if (displayOrder == 0)
                {
                    personLinkQuery = personQry.Select(p => p.NickName + " " + p.LastName);
                }
                else
                {
                    personLinkQuery = personQry.Select(p => p.LastName + ", " + p.NickName);
                }
            }

            return(SelectExpressionExtractor.Extract <Rock.Model.Person>(personLinkQuery, entityIdProperty, "p"));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var attributeGuid = selection.AsGuid();

            var groupAttributeEntityFields = GetGroupAttributeEntityFields();

            var entityField = groupAttributeEntityFields.FirstOrDefault(f => f.AttributeGuid == attributeGuid);

            if (entityField != null)
            {
                var serviceInstance = new AttributeValueService(context);
                var valuesQuery     = serviceInstance.Queryable()
                                      .Where(x => x.Attribute.Guid == attributeGuid)
                                      .Select(x => new { x.EntityId, x.Value });

                var groupMemberService = new GroupMemberService(context);

                var resultQuery = groupMemberService.Queryable()
                                  .Select(gm => valuesQuery.FirstOrDefault(v => v.EntityId == gm.GroupId).Value);

                return(SelectExpressionExtractor.Extract(resultQuery, entityIdProperty, "gm"));
            }

            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var values = selection.Split('|');

            IQueryable <int> memberCountQuery;

            if (values.Length >= 2)
            {
                bool?isLeader = values[0].AsBooleanOrNull();
                GroupMemberStatus?memberStatusValue = (GroupMemberStatus?)values[1].AsIntegerOrNull();

                memberCountQuery = new GroupService(context).Queryable()
                                   .Select(p => p.Members.Count(a =>
                                                                (!memberStatusValue.HasValue || a.GroupMemberStatus == memberStatusValue) &&
                                                                (!isLeader.HasValue || (a.GroupRole.IsLeader == isLeader.Value))));
            }
            else
            {
                memberCountQuery = new GroupService(context).Queryable().Select(p => (int)0);
            }

            var selectExpression = SelectExpressionExtractor.Extract <Rock.Model.Group>(memberCountQuery, entityIdProperty, "p");

            return(selectExpression);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the recipient person identifier expression.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public Expression GetRecipientPersonIdExpression(System.Data.Entity.DbContext dbContext, MemberExpression entityIdProperty, string selection)
        {
            var rockContext = dbContext as RockContext;

            if (rockContext != null)
            {
                Guid adultGuid  = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
                Guid childGuid  = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid();
                Guid familyGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

                var familyGroupMembers = new GroupMemberService(rockContext).Queryable()
                                         .Where(m => m.Group.GroupType.Guid == familyGuid);

                // this returns Enumerable of ids for Parents per row. The Grid then uses ListDelimiterField to convert the list into Parents Names
                var personParentsQuery = new PersonService(rockContext).Queryable()
                                         .Select(p => familyGroupMembers.Where(s => s.PersonId == p.Id && s.GroupRole.Guid == childGuid)
                                                 .SelectMany(m => m.Group.Members)
                                                 .Where(m => m.GroupRole.Guid == adultGuid)
                                                 .OrderBy(m => m.Group.Members.FirstOrDefault(x => x.PersonId == p.Id).GroupOrder ?? int.MaxValue)
                                                 .ThenBy(m => m.Person.Gender)
                                                 .Select(m => m.Person.Id).AsEnumerable());

                var selectParentsExpression = SelectExpressionExtractor.Extract(personParentsQuery, entityIdProperty, "p");

                return(selectParentsExpression);
            }

            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            //// Spouse is determined if all these conditions are met
            //// 1) Adult in the same family as Person (GroupType = Family, GroupRole = Adult, and in same Group)
            //// 2) Opposite Gender as Person
            //// 3) Both Persons are Married

            var  selectionParts  = selection.Split('|');
            bool includeLastname = selectionParts.Length > 0 && selectionParts[0].AsBoolean();

            Guid adultGuid             = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
            Guid marriedGuid           = Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid();
            int  marriedDefinedValueId = DefinedValueCache.Get(marriedGuid).Id;
            Guid familyGuid            = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

            var familyGroupMembers = new GroupMemberService(context).Queryable()
                                     .Where(m => m.Group.GroupType.Guid == familyGuid);

            var personSpouseQuery = new PersonService(context).Queryable()
                                    .Select(p => familyGroupMembers.Where(s => s.PersonId == p.Id && s.Person.MaritalStatusValueId == marriedDefinedValueId && s.GroupRole.Guid == adultGuid)
                                            .SelectMany(m => m.Group.Members)
                                            .Where(m =>
                                                   m.PersonId != p.Id &&
                                                   m.GroupRole.Guid == adultGuid &&
                                                   m.Person.Gender != p.Gender &&
                                                   m.Person.MaritalStatusValueId == marriedDefinedValueId &&
                                                   !m.Person.IsDeceased)
                                            .OrderBy(m => m.Group.Members.FirstOrDefault(x => x.PersonId == p.Id).GroupOrder ?? int.MaxValue)
                                            .Select(m => includeLastname ? m.Person.NickName + " " + m.Person.LastName : m.Person.NickName).FirstOrDefault());

            var selectSpouseExpression = SelectExpressionExtractor.Extract(personSpouseQuery, entityIdProperty, "p");

            return(selectSpouseExpression);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            string[] selectionValues          = selection.Split('|');
            Guid?    phoneNumberTypeValueGuid = null;

            if (selectionValues.Length >= 1)
            {
                phoneNumberTypeValueGuid = selectionValues[0].AsGuidOrNull();
            }

            if (!phoneNumberTypeValueGuid.HasValue)
            {
                phoneNumberTypeValueGuid = Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME.AsGuid();
            }

            int phoneNumberTypeValueId = DefinedValueCache.Get(phoneNumberTypeValueGuid.Value).Id;

            // NOTE: This actually selects the entire PhoneNumber record instead of just one field. This is done intentionally so that the Grid will call the .ToString() method of PhoneNumber which formats it correctly
            var personPhoneNumberQuery = new PersonService(context).Queryable()
                                         .Select(p => p.PhoneNumbers.FirstOrDefault(a => a.NumberTypeValueId == phoneNumberTypeValueId));

            var selectExpression = SelectExpressionExtractor.Extract(personPhoneNumberQuery, entityIdProperty, "p");

            return(selectExpression);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the recipient person identifier expression.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public Expression GetRecipientPersonIdExpression( System.Data.Entity.DbContext dbContext, MemberExpression entityIdProperty, string selection )
        {
            var rockContext = dbContext as RockContext;
            if ( rockContext != null )
            {
                Guid adultGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
                Guid childGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid();
                Guid familyGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

                var familyGroupMembers = new GroupMemberService( rockContext ).Queryable()
                    .Where( m => m.Group.GroupType.Guid == familyGuid );

                // this returns Enumerable of KidInfo per row. See this.GetGridField to see how it is processed 
                var personChildrenQuery = new PersonService( rockContext ).Queryable()
                    .Select( p => familyGroupMembers.Where( s => s.PersonId == p.Id && s.GroupRole.Guid == adultGuid )
                        .SelectMany( m => m.Group.Members )
                        .Where( m => m.GroupRole.Guid == childGuid )
                        .OrderBy( m => m.Group.Members.FirstOrDefault( x => x.PersonId == p.Id ).GroupOrder ?? int.MaxValue )
                        .ThenBy( m => m.Person.BirthYear ).ThenBy( m => m.Person.BirthMonth ).ThenBy( m => m.Person.BirthDay )
                        .Select( m => m.Person.Id ).AsEnumerable() );

                var selectChildrenExpression = SelectExpressionExtractor.Extract( personChildrenQuery, entityIdProperty, "p" );

                return selectChildrenExpression;
            }

            return null;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            string[] selectionValues = selection.Split('|');
            int?     noteTypeId      = null;

            if (selectionValues.Count() > 0)
            {
                noteTypeId = selectionValues[0].AsIntegerOrNull();
            }

            var entityTypeIdPerson = EntityTypeCache.GetId <Rock.Model.Person>();

            // only get PersonNotes that are not Private
            var qryNotes = new NoteService(context).Queryable().Where(a => a.NoteType.EntityTypeId == entityTypeIdPerson && a.IsPrivateNote == false);

            if (noteTypeId.HasValue)
            {
                qryNotes = qryNotes.Where(n => n.NoteTypeId == noteTypeId.Value);
            }

            var qryPersonNotes = new PersonService(context).Queryable().Select(p => qryNotes.Where(xx => xx.Id == qryNotes.Where(a => a.EntityId == p.Id).Max(x => x.Id)).Select(s => s.Text).FirstOrDefault());

            var selectNoteExpression = SelectExpressionExtractor.Extract(qryPersonNotes, entityIdProperty, "p");

            return(selectNoteExpression);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var settings = new SelectSettings(selection);

            var entityFields = GetGroupMemberAttributes();
            var entityField  = entityFields.FirstOrDefault(f => f.Name == settings.AttributeKey);

            if (entityField == null)
            {
                return(null);
            }

            var serviceInstance = new AttributeValueService(context);

            var entityTypeId = EntityTypeCache.GetId(typeof(Rock.Model.GroupMember));

            var valuesQuery = serviceInstance.Queryable()
                              .Where(x => x.Attribute.Key == settings.AttributeKey && x.Attribute.EntityTypeId == entityTypeId)
                              .Select(x => new { x.EntityId, x.Value });

            var groupMemberService = new GroupMemberService(context);

            var resultQuery = groupMemberService.Queryable()
                              .Select(gm => valuesQuery.FirstOrDefault(v => v.EntityId == gm.Id).Value);

            var exp = SelectExpressionExtractor.Extract(resultQuery, entityIdProperty, "gm");

            return(exp);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 2)
            {
                GroupMemberService groupMemberService = new GroupMemberService(context);
                Guid groupTypeGuid = selectionValues[0].AsGuid();

                var groupMemberServiceQry = groupMemberService.Queryable().Where(xx => xx.Group.GroupType.Guid == groupTypeGuid);

                var groupRoleGuids = selectionValues[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => n.AsGuid()).ToList();
                if (groupRoleGuids.Count() > 0)
                {
                    groupMemberServiceQry = groupMemberServiceQry.Where(xx => groupRoleGuids.Contains(xx.GroupRole.Guid));
                }

                var qry = new PersonService(context).Queryable()
                          .Select(p => groupMemberServiceQry.Any(xx => xx.PersonId == p.Id));

                Expression selectExpression = SelectExpressionExtractor.Extract <Rock.Model.Person>(qry, entityIdProperty, "p");

                return(selectExpression);
            }

            return(null);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override System.Linq.Expressions.Expression GetExpression(Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection)
        {
            bool showAsLink   = this.GetAttributeValueFromSelection("ShowAsLink", selection).AsBooleanOrNull() ?? false;
            int  displayOrder = this.GetAttributeValueFromSelection("DisplayOrder", selection).AsIntegerOrNull() ?? 0;
            var  personQry    = new PersonService(context).Queryable();
            IQueryable <string> personLinkQuery;

            string basePersonUrl = System.Web.VirtualPathUtility.ToAbsolute("~/Person/");

            if (showAsLink)
            {
                // return string in format: <a href='/person/{personId}'>LastName, NickName</a>
                if (displayOrder == 0)
                {
                    personLinkQuery = personQry.Select(p => "<a href='" + basePersonUrl + p.Id.ToString() + "'>" + p.NickName + " " + p.LastName + "</a>");
                }
                else
                {
                    personLinkQuery = personQry.Select(p => "<a href='" + basePersonUrl + p.Id.ToString() + "'>" + p.LastName + ", " + p.NickName + "</a>");
                }
            }
            else
            {
                if (displayOrder == 0)
                {
                    personLinkQuery = personQry.Select(p => p.NickName + " " + p.LastName);
                }
                else
                {
                    personLinkQuery = personQry.Select(p => p.LastName + ", " + p.NickName);
                }
            }

            return(SelectExpressionExtractor.Extract(personLinkQuery, entityIdProperty, "p"));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override System.Linq.Expressions.Expression GetExpression(Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection)
        {
            bool showAsLink = this.GetAttributeValueFromSelection("ShowAsLink", selection).AsBooleanOrNull() ?? false;

            var memberQuery = new GroupMemberService(context).Queryable();

            IQueryable <FormattedDataValue> groupLinkQuery;

            if (showAsLink)
            {
                groupLinkQuery = memberQuery.Select(gm => new HtmlLinkDataValue {
                    SourceValue = gm.Group.Name, Url = "/group/" + gm.GroupId.ToString()
                });
            }
            else
            {
                groupLinkQuery = memberQuery.Select(gm => new FormattedDataValue {
                    SourceValue = gm.Group.Name
                });
            }

            var exp = SelectExpressionExtractor.Extract(groupLinkQuery, entityIdProperty, "gm");

            return(exp);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            Guid adultGuid  = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
            Guid childGuid  = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid();
            Guid familyGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

            var familyGroupMembers = new GroupMemberService(context).Queryable()
                                     .Where(m => m.Group.GroupType.Guid == familyGuid);

            // this returns Enumerable of KidInfo per row. See this.GetGridField to see how it is processed
            var personChildrenQuery = new PersonService(context).Queryable()
                                      .Select(p => familyGroupMembers.Where(s => s.PersonId == p.Id && s.GroupRole.Guid == adultGuid)
                                              .SelectMany(m => m.Group.Members)
                                              .Where(m => m.GroupRole.Guid == childGuid)
                                              .OrderBy(m => m.Person.BirthYear).ThenBy(m => m.Person.BirthMonth).ThenBy(m => m.Person.BirthDay)
                                              .Select(m => new KidInfo
            {
                NickName      = m.Person.NickName,
                LastName      = m.Person.LastName,
                SuffixValueId = m.Person.SuffixValueId,
                Gender        = m.Person.Gender,
                BirthDate     = m.Person.BirthDate
            }).AsEnumerable());

            var selectChildrenExpression = SelectExpressionExtractor.Extract(personChildrenQuery, entityIdProperty, "p");

            return(selectChildrenExpression);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override System.Linq.Expressions.Expression GetExpression(Rock.Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection)
        {
            var attributeValueService           = new AttributeValueService(context);
            var roomReservationGroupAttGuid     = ZoomGuid.Attribute.ROOM_RESERVATION_GROUP_ATTRIBUTE.AsGuid();
            var reservationLocationEntityTypeId = new EntityTypeService(context).GetNoTracking(com.bemaservices.RoomManagement.SystemGuid.EntityType.RESERVATION_LOCATION.AsGuid()).Id;

            var resGroupAttValues = attributeValueService.Queryable()
                                    .Where(x => x.Attribute.Guid == roomReservationGroupAttGuid)
                                    .Select(x => new { EntityId = x.EntityId, Value = x.Value });

            var groupQuery = new GroupService(context).Queryable()
                             .Select(g => new { GuidString = g.Guid.ToString(), GroupName = g.Name + " (" + g.Id.ToString() + ")" });

            var reservationQuery = new ReservationService(context).Queryable()
                                   .Select(r => new { r.Id });

            var reservationlocationQuery = new ReservationLocationService(context).Queryable()
                                           .Select(rl => new { rl.Id, rl.ReservationId });

            var occurrenceService = new RoomOccurrenceService(context);

            var resultQuery = occurrenceService.Queryable("ReservationLocation")
                              .Select(ro => groupQuery.FirstOrDefault(g => resGroupAttValues.FirstOrDefault(v => reservationQuery.FirstOrDefault(r => reservationlocationQuery.FirstOrDefault(rl => ro.EntityTypeId == reservationLocationEntityTypeId && rl.Id == ro.EntityId).ReservationId == r.Id).Id == v.EntityId).Value.Contains(g.GuidString)).GroupName);

            return(SelectExpressionExtractor.Extract(resultQuery, entityIdProperty, "ro"));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var qryGroupService = new GroupService(context).Queryable();

            Expression <Func <Rock.Model.GroupMember, bool> > memberWhereGroupType  = a => 1 == 1;
            Expression <Func <Rock.Model.GroupMember, bool> > memberWhereGroupRoles = a => 1 == 1;
            Expression <Func <Rock.Model.GroupMember, bool> > memberWhereStatus     = a => 1 == 1;

            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 3)
            {
                GroupMemberService groupMemberService = new GroupMemberService(context);
                int?groupTypeId = null;

                Guid groupTypeGuid = selectionValues[1].AsGuid();

                var groupType = GroupTypeCache.Get(groupTypeGuid);
                if (groupType != null)
                {
                    groupTypeId = groupType.Id;
                }

                if (groupTypeId.HasValue)
                {
                    memberWhereGroupType = xx => xx.Group.GroupTypeId == groupTypeId;
                }

                var        groupRoleGuids = selectionValues[2].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => n.AsGuid()).ToList();
                List <int> groupRoleIds   = null;
                if (groupRoleGuids.Count() > 0)
                {
                    groupRoleIds          = new GroupTypeRoleService(context).Queryable().Where(a => groupRoleGuids.Contains(a.Guid)).Select(a => a.Id).ToList();
                    memberWhereGroupRoles = xx => groupRoleIds.Contains(xx.GroupRoleId);
                }

                GroupMemberStatus?groupMemberStatus = selectionValues[3].ConvertToEnumOrNull <GroupMemberStatus>();

                if (groupMemberStatus.HasValue)
                {
                    memberWhereStatus = xx => xx.GroupMemberStatus == groupMemberStatus.Value;
                }
            }

            var memberListQuery = qryGroupService.Select(p => p.Members.AsQueryable()
                                                         .Where(memberWhereGroupType)
                                                         .Where(memberWhereGroupRoles)
                                                         .Where(memberWhereStatus)
                                                         .Select(m => new MemberInfo
            {
                NickName      = m.Person.NickName,
                LastName      = m.Person.LastName,
                SuffixValueId = m.Person.SuffixValueId,
                PersonId      = m.PersonId,
                GroupMemberId = m.Id
            }).OrderBy(a => a.LastName).ThenBy(a => a.NickName));

            var selectChildrenExpression = SelectExpressionExtractor.Extract(memberListQuery, entityIdProperty, "p");

            return(selectChildrenExpression);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Gets the recipient person identifier expression.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public Expression GetRecipientPersonIdExpression(System.Data.Entity.DbContext dbContext, MemberExpression entityIdProperty, string selection)
        {
            var rockContext = dbContext as RockContext;

            if (rockContext != null)
            {
                var qryGroupService = new GroupService(rockContext).Queryable();

                Expression <Func <Rock.Model.GroupMember, bool> > memberWhereGroupType  = a => 1 == 1;
                Expression <Func <Rock.Model.GroupMember, bool> > memberWhereGroupRoles = a => 1 == 1;
                Expression <Func <Rock.Model.GroupMember, bool> > memberWhereStatus     = a => 1 == 1;

                string[] selectionValues = selection.Split('|');
                if (selectionValues.Length >= 3)
                {
                    GroupMemberService groupMemberService = new GroupMemberService(rockContext);
                    int?groupTypeId = null;

                    Guid groupTypeGuid = selectionValues[1].AsGuid();

                    var groupType = GroupTypeCache.Get(groupTypeGuid);
                    if (groupType != null)
                    {
                        groupTypeId = groupType.Id;
                    }

                    if (groupTypeId.HasValue)
                    {
                        memberWhereGroupType = xx => xx.Group.GroupTypeId == groupTypeId;
                    }

                    var        groupRoleGuids = selectionValues[2].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => n.AsGuid()).ToList();
                    List <int> groupRoleIds   = null;
                    if (groupRoleGuids.Count() > 0)
                    {
                        groupRoleIds          = new GroupTypeRoleService(rockContext).Queryable().Where(a => groupRoleGuids.Contains(a.Guid)).Select(a => a.Id).ToList();
                        memberWhereGroupRoles = xx => groupRoleIds.Contains(xx.GroupRoleId);
                    }

                    GroupMemberStatus?groupMemberStatus = selectionValues[3].ConvertToEnumOrNull <GroupMemberStatus>();

                    if (groupMemberStatus.HasValue)
                    {
                        memberWhereStatus = xx => xx.GroupMemberStatus == groupMemberStatus.Value;
                    }
                }

                var memberListQuery = qryGroupService.Select(p => p.Members.AsQueryable()
                                                             .Where(memberWhereGroupType)
                                                             .Where(memberWhereGroupRoles)
                                                             .Where(memberWhereStatus)
                                                             .Select(m => m.PersonId));

                var selectChildrenExpression = SelectExpressionExtractor.Extract(memberListQuery, entityIdProperty, "p");

                return(selectChildrenExpression);
            }

            return(null);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the recipient person identifier expression.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public Expression GetRecipientPersonIdExpression(System.Data.Entity.DbContext dbContext, MemberExpression entityIdProperty, string selection)
        {
            var rockContext = dbContext as RockContext;

            if (rockContext != null)
            {
                Guid adultGuid             = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
                Guid marriedGuid           = Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid();
                int  marriedDefinedValueId = DefinedValueCache.Get(marriedGuid).Id;
                Guid familyGuid            = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid();

                var familyGroupMembers = new GroupMemberService(rockContext).Queryable()
                                         .Where(m => m.Group.GroupType.Guid == familyGuid);

                var personSpouseQuery = new PersonService(rockContext).Queryable()
                                        .Select(p => familyGroupMembers.Where(s => s.PersonId == p.Id && s.Person.MaritalStatusValueId == marriedDefinedValueId && s.GroupRole.Guid == adultGuid)
                                                .SelectMany(m => m.Group.Members)
                                                .Where(m =>
                                                       m.PersonId != p.Id &&
                                                       m.GroupRole.Guid == adultGuid &&
                                                       m.Person.Gender != p.Gender &&
                                                       m.Person.MaritalStatusValueId == marriedDefinedValueId &&
                                                       !m.Person.IsDeceased)
                                                .OrderBy(m => m.Group.Members.FirstOrDefault(x => x.PersonId == p.Id).GroupOrder ?? int.MaxValue)
                                                .Select(m => m.Person.Id).FirstOrDefault());

                var selectSpouseExpression = SelectExpressionExtractor.Extract(personSpouseQuery, entityIdProperty, "p");

                return(selectSpouseExpression);
            }

            return(null);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var allRelatedPeopleQuery = GetAllRelatedPeopleQuery(context, entityIdProperty, selection);
            var personQuery           = new PersonService(context).Queryable().Select(p => allRelatedPeopleQuery.Where(rpi => rpi.RelatedToPersonId == p.Id).AsEnumerable());
            var selectExpression      = SelectExpressionExtractor.Extract(personQuery, entityIdProperty, "p");

            return(selectExpression);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            SelectionData data = DeserializeSelectionData(selection);

            var query = LinqSelectForProperty(context, typeof(TargetEntityType), data.Property, "o");

            return(SelectExpressionExtractor.Extract(query, entityIdProperty, "o"));
        }
Ejemplo n.º 23
0
        private Expression GetDefaultSelectExpression(RockContext context, MemberExpression entityIdProperty)
        {
            var resultQuery = new GroupService(context).Queryable().Select(p => (decimal)0);

            var selectExpression = SelectExpressionExtractor.Extract(resultQuery, entityIdProperty, "p");

            return(selectExpression);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var groupQuery = new GroupService(context).Queryable()
                             .Select(p => p.GroupType.Name);

            var selectExpression = SelectExpressionExtractor.Extract(groupQuery, entityIdProperty, "p");

            return(selectExpression);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var prayerRequestQuery = new PrayerRequestService(context).Queryable()
                                     .Select(p => p.Category.Name);

            var selectExpression = SelectExpressionExtractor.Extract(prayerRequestQuery, entityIdProperty, "p");

            return(selectExpression);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var totalAmountQuery = new BenevolenceRequestService(context).Queryable()
                                   .Select(p => p.BenevolenceResults.Sum(a => a.Amount));

            var selectTotalAmountExpression = SelectExpressionExtractor.Extract(totalAmountQuery, entityIdProperty, "p");

            return(selectTotalAmountExpression);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var totalAmountQuery = new FinancialTransactionService(context).Queryable()
                                   .Select(p => p.TransactionDetails.Sum(a => a.Amount));

            var selectTotalAmountExpression = SelectExpressionExtractor.Extract(totalAmountQuery, entityIdProperty, "p");

            return(selectTotalAmountExpression);
        }
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            var groupType   = GroupTypeCache.Get(selection.AsGuid());
            int groupTypeId = (groupType != null) ? groupType.Id : 0;

            var qry = new PersonService(context).Queryable()
                      .Select(p => RockUdfHelper.ufnGroup_GetGeofencingGroupNames(p.Id, groupTypeId));

            return(SelectExpressionExtractor.Extract(qry, entityIdProperty, "p"));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override System.Linq.Expressions.Expression GetExpression(Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection)
        {
            var service = new GroupMemberService(context);

            var query = service.Queryable()
                        .Select(gm => gm.GroupMemberStatus.ToString());

            var exp = SelectExpressionExtractor.Extract(query, entityIdProperty, "gm");

            return(exp);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityIdProperty">The entity identifier property.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection)
        {
            Guid?groupLocationTypeValueGuid = selection.AsGuid();

            var groupLocationQuery = new GroupService(context).Queryable()
                                     .Select(p => p.GroupLocations.Where(gl => gl.GroupLocationTypeValue.Guid == groupLocationTypeValueGuid).Select(gl => gl.Location).FirstOrDefault());

            var selectExpression = SelectExpressionExtractor.Extract(groupLocationQuery, entityIdProperty, "p");

            return(selectExpression);
        }