/// <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; } } }
/// <summary> /// Updates the group member requirement result. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="personId">The person identifier.</param> /// <param name="meetsGroupRequirement">The meets group requirement.</param> public void UpdateGroupMemberRequirementResult(RockContext rockContext, int personId, 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 == groupRequirement.GroupId); 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; } } }
public void UpdateGroupMemberRequirementResult(RockContext rockContext, int personId, MeetsGroupRequirement meetsGroupRequirement) { if (this.GroupId.HasValue) { UpdateGroupMemberRequirementResult(rockContext, personId, this.GroupId.Value, meetsGroupRequirement); } else { // the new method needs to be used if this is a GroupTypeId GroupRequirement throw new NotSupportedException(); } }