示例#1
0
        /// <summary>
        /// Updates the group member requirement result.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="personId">The person identifier.</param>
        /// <param name="groupId">The group identifier.</param>
        /// <param name="meetsGroupRequirement">The meets group requirement.</param>
        public void UpdateGroupMemberRequirementResult(RockContext rockContext, int personId, int groupId, MeetsGroupRequirement meetsGroupRequirement)
        {
            GroupRequirement groupRequirement = this;
            var currentDateTime = RockDateTime.Now;
            GroupMemberRequirementService groupMemberRequirementService = new GroupMemberRequirementService(rockContext);
            var groupMemberService = new GroupMemberService(rockContext);
            var groupMemberQry     = groupMemberService.Queryable(true).Where(a => a.PersonId == personId && a.GroupId == groupId &&
                                                                              (
                                                                                  (groupRequirement.GroupId.HasValue && groupRequirement.GroupId == a.GroupId)
                                                                                  ||
                                                                                  (groupRequirement.GroupTypeId.HasValue && groupRequirement.GroupTypeId == a.Group.GroupTypeId)
                                                                              ));

            if (this.GroupRoleId != null)
            {
                groupMemberQry = groupMemberQry.Where(a => a.GroupRoleId == this.GroupRoleId);
            }

            foreach (var groupMemberId in groupMemberQry.Select(a => a.Id))
            {
                var groupMemberRequirement = groupMemberRequirementService.Queryable().Where(a => a.GroupMemberId == groupMemberId && a.GroupRequirementId == groupRequirement.Id).FirstOrDefault();
                if (groupMemberRequirement == null)
                {
                    groupMemberRequirement = new GroupMemberRequirement();
                    groupMemberRequirement.GroupMemberId      = groupMemberId;
                    groupMemberRequirement.GroupRequirementId = groupRequirement.Id;
                    groupMemberRequirementService.Add(groupMemberRequirement);
                }

                groupMemberRequirement.LastRequirementCheckDateTime = currentDateTime;

                if ((meetsGroupRequirement == MeetsGroupRequirement.Meets) || (meetsGroupRequirement == MeetsGroupRequirement.MeetsWithWarning))
                {
                    // they meet the requirement so update the Requirement Met Date/Time
                    groupMemberRequirement.RequirementMetDateTime  = currentDateTime;
                    groupMemberRequirement.RequirementFailDateTime = null;
                }
                else
                {
                    // they don't meet the requirement so set the Requirement Met Date/Time to null
                    groupMemberRequirement.RequirementMetDateTime  = null;
                    groupMemberRequirement.RequirementFailDateTime = currentDateTime;
                }

                if (meetsGroupRequirement == MeetsGroupRequirement.MeetsWithWarning)
                {
                    if (!groupMemberRequirement.RequirementWarningDateTime.HasValue)
                    {
                        // they have a warning for the requirement, and didn't have a warning already
                        groupMemberRequirement.RequirementWarningDateTime = currentDateTime;
                    }
                }
                else
                {
                    // no warning, so set to null
                    groupMemberRequirement.RequirementWarningDateTime = null;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Clones this GroupMemberRequirement object to a new GroupMemberRequirement object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static GroupMemberRequirement Clone(this GroupMemberRequirement source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as GroupMemberRequirement);
     }
     else
     {
         var target = new GroupMemberRequirement();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
示例#3
0
 /// <summary>
 /// Copies the properties from another GroupMemberRequirement object to this GroupMemberRequirement object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this GroupMemberRequirement target, GroupMemberRequirement source)
 {
     target.Id                           = source.Id;
     target.ForeignGuid                  = source.ForeignGuid;
     target.ForeignKey                   = source.ForeignKey;
     target.GroupMemberId                = source.GroupMemberId;
     target.GroupRequirementId           = source.GroupRequirementId;
     target.LastRequirementCheckDateTime = source.LastRequirementCheckDateTime;
     target.RequirementFailDateTime      = source.RequirementFailDateTime;
     target.RequirementMetDateTime       = source.RequirementMetDateTime;
     target.RequirementWarningDateTime   = source.RequirementWarningDateTime;
     target.CreatedDateTime              = source.CreatedDateTime;
     target.ModifiedDateTime             = source.ModifiedDateTime;
     target.CreatedByPersonAliasId       = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId      = source.ModifiedByPersonAliasId;
     target.Guid                         = source.Guid;
     target.ForeignId                    = source.ForeignId;
 }
示例#4
0
        /// <summary>
        /// Updates the group member requirement result.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="personId">The person identifier.</param>
        /// <param name="groupId">The group identifier.</param>
        /// <param name="meetsGroupRequirement">The meets group requirement.</param>
        public void UpdateGroupMemberRequirementResult(RockContext rockContext, int personId, int groupId, MeetsGroupRequirement meetsGroupRequirement)
        {
            GroupRequirement groupRequirement = this;
            var currentDateTime = RockDateTime.Now;
            GroupMemberRequirementService groupMemberRequirementService = new GroupMemberRequirementService(rockContext);
            var groupMemberService = new GroupMemberService(rockContext);
            var groupMemberQry     = groupMemberService.Queryable(true).Where(a => a.PersonId == personId && a.GroupId == groupId);

            if (groupRequirement.GroupId.HasValue)
            {
                groupMemberQry = groupMemberQry.Where(g => g.GroupId == groupRequirement.GroupId);
            }
            else if (groupRequirement.GroupTypeId.HasValue)
            {
                groupMemberQry = groupMemberQry.Where(g => g.Group.GroupTypeId == groupRequirement.GroupTypeId);
            }
            else
            {
                // shouldn't happen, but grouprequirement doesn't have a groupId or a GroupTypeId
                return;
            }



            if (this.GroupRoleId != null)
            {
                groupMemberQry = groupMemberQry.Where(a => a.GroupRoleId == this.GroupRoleId);
            }

            // just in case the same person is in the same group multiple times, get a list of the groupMember records for this person
            foreach (var groupMemberId in groupMemberQry.Select(a => a.Id))
            {
                var groupMemberRequirement = groupMemberRequirementService.Queryable().Where(a => a.GroupMemberId == groupMemberId && a.GroupRequirementId == groupRequirement.Id).FirstOrDefault();
                if (groupMemberRequirement == null)
                {
                    groupMemberRequirement = new GroupMemberRequirement();
                    groupMemberRequirement.GroupMemberId      = groupMemberId;
                    groupMemberRequirement.GroupRequirementId = groupRequirement.Id;
                    groupMemberRequirementService.Add(groupMemberRequirement);
                }

                groupMemberRequirement.LastRequirementCheckDateTime = currentDateTime;

                if ((meetsGroupRequirement == MeetsGroupRequirement.Meets) || (meetsGroupRequirement == MeetsGroupRequirement.MeetsWithWarning))
                {
                    // they meet the requirement so update the Requirement Met Date/Time
                    groupMemberRequirement.RequirementMetDateTime  = currentDateTime;
                    groupMemberRequirement.RequirementFailDateTime = null;
                }
                else
                {
                    // they don't meet the requirement so set the Requirement Met Date/Time to null
                    groupMemberRequirement.RequirementMetDateTime  = null;
                    groupMemberRequirement.RequirementFailDateTime = currentDateTime;
                }

                if (meetsGroupRequirement == MeetsGroupRequirement.MeetsWithWarning)
                {
                    if (!groupMemberRequirement.RequirementWarningDateTime.HasValue)
                    {
                        // they have a warning for the requirement, and didn't have a warning already
                        groupMemberRequirement.RequirementWarningDateTime = currentDateTime;
                    }
                }
                else
                {
                    // no warning, so set to null
                    groupMemberRequirement.RequirementWarningDateTime = null;
                }
            }
        }