/// <summary>
/// Determines whether this is a new group member (just added) or if either Person or Role is different than what is stored in the database
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
public bool IsNewOrChangedGroupMember(RockContext rockContext)
{
if (this.Id == 0)
{
// new group member
return(true);
}
else
{
var groupMemberService = new GroupMemberService(rockContext);
var databaseGroupMemberRecord = groupMemberService.Get(this.Id);
// existing groupmember record, but person or role was changed
var hasChanged = this.PersonId != databaseGroupMemberRecord.PersonId || this.GroupRoleId != databaseGroupMemberRecord.GroupRoleId;
if (!hasChanged)
{
var entry = rockContext.Entry(this);
if (entry != null)
{
hasChanged = rockContext.Entry(this).Property("PersonId")?.IsModified == true || rockContext.Entry(this).Property("GroupRoleId")?.IsModified == true;
}
}
return(hasChanged);
}
}