/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService(rockContext); var personService = new PersonService(rockContext); int personId = this.PageParameter("PersonId").AsInteger(); int recordStatusInactiveId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id; //// select person duplicate records //// list duplicates that aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges. Also, don't include records where both the Person and Duplicate are inactive var qryPersonDuplicates = personDuplicateService.Queryable() .Where(a => a.PersonAlias.PersonId == personId && !a.IsConfirmedAsNotDuplicate && !a.IgnoreUntilScoreChanges); if (this.GetAttributeValue("IncludeInactive").AsBoolean() == false) { qryPersonDuplicates = qryPersonDuplicates.Where(a => !(a.PersonAlias.Person.RecordStatusValueId == recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId == recordStatusInactiveId)); } var qry = qryPersonDuplicates.Select(s => new { PersonId = s.DuplicatePersonAlias.Person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = s.Id, DuplicatePerson = s.DuplicatePersonAlias.Person, s.ConfidenceScore, IsComparePerson = true }); double?confidenceScoreLow = GetAttributeValue("ConfidenceScoreLow").AsDoubleOrNull(); if (confidenceScoreLow.HasValue) { qry = qry.Where(a => a.ConfidenceScore >= confidenceScoreLow); } qry = qry.OrderByDescending(a => a.ConfidenceScore).ThenBy(a => a.DuplicatePerson.LastName).ThenBy(a => a.DuplicatePerson.FirstName); var gridList = qry.ToList(); // put the person we are comparing the duplicates to at the top of the list var person = personService.Get(personId); gridList.Insert( 0, new { PersonId = person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = 0, DuplicatePerson = person, ConfidenceScore = (double?)null, IsComparePerson = false }); nbNoDuplicatesMessage.Visible = gridList.Count == 1; gList.DataSource = gridList; gList.DataBind(); }
/// <summary> /// Handles the Click event of the btnIgnoreDuplicate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnIgnoreDuplicate_Click(object sender, EventArgs e) { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService(rockContext); int personDuplicateId = (sender as LinkButton).CommandArgument.AsInteger(); var personDuplicate = personDuplicateService.Get(personDuplicateId); personDuplicate.IgnoreUntilScoreChanges = true; rockContext.SaveChanges(); BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService(rockContext); int recordStatusInactiveId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id; // list duplicates that aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges. Also, don't include records where both the Person and Duplicate are inactive var personDuplicateQry = personDuplicateService.Queryable() .Where(a => !a.IsConfirmedAsNotDuplicate) .Where(a => !a.IgnoreUntilScoreChanges) .Where(a => a.PersonAlias.Person.RecordStatusValueId != recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId != recordStatusInactiveId); double?confidenceScoreLow = GetAttributeValue("ConfidenceScoreLow").AsDoubleOrNull(); if (confidenceScoreLow.HasValue) { personDuplicateQry = personDuplicateQry.Where(a => a.ConfidenceScore > confidenceScoreLow); } var groupByQry = personDuplicateQry.GroupBy(a => a.PersonAlias.Person); var qry = groupByQry.Select(a => new { PersonId = a.Key.Id, LastName = a.Key.LastName, FirstName = a.Key.FirstName, MatchCount = a.Count(), MaxConfidenceScore = a.Max(s => s.ConfidenceScore), PersonModifiedDateTime = a.Key.ModifiedDateTime, CreatedByPerson = a.Key.CreatedByPersonAlias.Person.FirstName + " " + a.Key.CreatedByPersonAlias.Person.LastName }); SortProperty sortProperty = gList.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderByDescending(a => a.MaxConfidenceScore).ThenBy(a => a.LastName).ThenBy(a => a.FirstName); } gList.DataSource = qry.ToList(); gList.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService(rockContext); int recordStatusInactiveId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id; int recordTypeBusinessId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid()).Id; // list duplicates that: // - aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges, // - don't have the PersonAlias and DuplicatePersonAlias records pointing to the same person ( occurs after two people have been merged but before the Calculate Person Duplicates job runs). // - don't include records where both the Person and Duplicate are inactive (block option) var personDuplicateQry = personDuplicateService.Queryable() .Where(a => !a.IsConfirmedAsNotDuplicate) .Where(a => !a.IgnoreUntilScoreChanges) .Where(a => a.PersonAlias.PersonId != a.DuplicatePersonAlias.PersonId); if (this.GetAttributeValue(AttributeKey.IncludeInactive).AsBoolean() == false) { personDuplicateQry = personDuplicateQry.Where(a => !(a.PersonAlias.Person.RecordStatusValueId == recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId == recordStatusInactiveId)); } if (this.GetAttributeValue(AttributeKey.IncludeBusinesses).AsBoolean() == false) { personDuplicateQry = personDuplicateQry.Where(a => !(a.PersonAlias.Person.RecordTypeValueId == recordTypeBusinessId || a.DuplicatePersonAlias.Person.RecordTypeValueId == recordTypeBusinessId)); } double?confidenceScoreLow = GetAttributeValue(AttributeKey.ConfidenceScoreLow).AsDoubleOrNull(); if (confidenceScoreLow.HasValue) { personDuplicateQry = personDuplicateQry.Where(a => a.ConfidenceScore > confidenceScoreLow); } var groupByQry = personDuplicateQry.GroupBy(a => a.PersonAlias.PersonId); var qryPerson = new PersonService(rockContext).Queryable(); var qry = groupByQry.Select(a => new { PersonId = a.Key, MatchCount = a.Count(), MaxConfidenceScore = a.Max(s => s.ConfidenceScore), }).Join( qryPerson, k1 => k1.PersonId, k2 => k2.Id, (personDuplicate, person) => new { PersonId = person.Id, person.SuffixValueId, person.SuffixValue, person.LastName, person.FirstName, PersonModifiedDateTime = person.ModifiedDateTime, CreatedByPerson = person.CreatedByPersonAlias.Person.FirstName + " " + person.CreatedByPersonAlias.Person.LastName, personDuplicate.MatchCount, personDuplicate.MaxConfidenceScore, person.AccountProtectionProfile, Campus = person.PrimaryCampus.Name }); SortProperty sortProperty = gList.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderByDescending(a => a.MaxConfidenceScore).ThenBy(a => a.LastName).ThenBy(a => a.FirstName); } var hasMultipleCampuses = CampusCache.All().Count(c => c.IsActive ?? true) > 1; if (!hasMultipleCampuses) { var campustColumn = gList.Columns.OfType <RockBoundField>().First(a => a.DataField == "Campus"); campustColumn.Visible = false; } // NOTE: Because the .Count() in the SetLinqDataSource() sometimes creates SQL that takes *significantly* // longer (> 26 minutes) to execute than the actual query (< 1s), we're changing this to a // simple .DataSource = ToList() for now until we have more time to consider an alternative solution. // Examples of the SQL generated to select the data vs to get the count are documented in our private // Asana card here: https://app.asana.com/0/21779865363458/553205615179451 //gList.SetLinqDataSource( qry ); gList.DataSource = qry.ToList(); gList.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var hasMultipleCampuses = CampusCache.All().Count(c => c.IsActive ?? true) > 1; if (!hasMultipleCampuses) { var campustColumn = gList.Columns.OfType <RockBoundField>().First(a => a.DataField == "Campus"); campustColumn.Visible = false; } RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService(rockContext); var personService = new PersonService(rockContext); int personId = this.PageParameter("PersonId").AsInteger(); int recordStatusInactiveId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id; int recordTypeBusinessId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid()).Id; //// select person duplicate records //// list duplicates that aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges. Also, don't include records where both the Person and Duplicate are inactive var qryPersonDuplicates = personDuplicateService.Queryable() .Where(a => a.PersonAlias.PersonId == personId && !a.IsConfirmedAsNotDuplicate && !a.IgnoreUntilScoreChanges); if (this.GetAttributeValue(AttributeKey.IncludeInactive).AsBoolean() == false) { qryPersonDuplicates = qryPersonDuplicates.Where(a => !(a.PersonAlias.Person.RecordStatusValueId == recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId == recordStatusInactiveId)); } if (this.GetAttributeValue(AttributeKey.IncludeBusinesses).AsBoolean() == false) { qryPersonDuplicates = qryPersonDuplicates.Where(a => !(a.PersonAlias.Person.RecordTypeValueId == recordTypeBusinessId || a.DuplicatePersonAlias.Person.RecordTypeValueId == recordTypeBusinessId)); } var qry = qryPersonDuplicates.Select(s => new { PersonId = s.DuplicatePersonAlias.Person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = s.Id, DuplicatePerson = s.DuplicatePersonAlias.Person, s.ConfidenceScore, IsComparePerson = true, Campus = s.DuplicatePersonAlias.Person.PrimaryCampus.Name }); double?confidenceScoreLow = GetAttributeValue(AttributeKey.ConfidenceScoreLow).AsDoubleOrNull(); if (confidenceScoreLow.HasValue) { qry = qry.Where(a => a.ConfidenceScore >= confidenceScoreLow); } qry = qry.OrderByDescending(a => a.ConfidenceScore).ThenBy(a => a.DuplicatePerson.LastName).ThenBy(a => a.DuplicatePerson.FirstName); var gridList = qry.ToList(); // put the person we are comparing the duplicates to at the top of the list var person = personService.Queryable().Include(p => p.PrimaryCampus).Where(p => p.Id == personId).FirstOrDefault(); if (person != null) { gridList.Insert( 0, new { PersonId = person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = 0, DuplicatePerson = person, ConfidenceScore = ( double? )null, IsComparePerson = false, Campus = person.PrimaryCampus?.Name }); nbNoDuplicatesMessage.Visible = gridList.Count == 1; gList.DataSource = gridList; gList.DataBind(); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "goBack", "history.go(-1);", true); } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService(rockContext); int recordStatusInactiveId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id; int recordTypeBusinessId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid()).Id; // list duplicates that: // - aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges, // - don't have the PersonAlias and DuplicatePersonAlias records pointing to the same person ( occurs after two people have been merged but before the Calculate Person Duplicates job runs). // - don't include records where both the Person and Duplicate are inactive (block option) var personDuplicateQry = personDuplicateService.Queryable() .Where(a => !a.IsConfirmedAsNotDuplicate) .Where(a => !a.IgnoreUntilScoreChanges) .Where(a => a.PersonAlias.PersonId != a.DuplicatePersonAlias.PersonId); if (this.GetAttributeValue("IncludeInactive").AsBoolean() == false) { personDuplicateQry = personDuplicateQry.Where(a => !(a.PersonAlias.Person.RecordStatusValueId == recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId == recordStatusInactiveId)); } if (this.GetAttributeValue("IncludeBusinesses").AsBoolean() == false) { personDuplicateQry = personDuplicateQry.Where(a => !(a.PersonAlias.Person.RecordTypeValueId == recordTypeBusinessId || a.DuplicatePersonAlias.Person.RecordTypeValueId == recordTypeBusinessId)); } double?confidenceScoreLow = GetAttributeValue("ConfidenceScoreLow").AsDoubleOrNull(); if (confidenceScoreLow.HasValue) { personDuplicateQry = personDuplicateQry.Where(a => a.ConfidenceScore > confidenceScoreLow); } var groupByQry = personDuplicateQry.GroupBy(a => a.PersonAlias.PersonId); var qryPerson = new PersonService(rockContext).Queryable(); var qry = groupByQry.Select(a => new { PersonId = a.Key, MatchCount = a.Count(), MaxConfidenceScore = a.Max(s => s.ConfidenceScore), }).Join( qryPerson, k1 => k1.PersonId, k2 => k2.Id, (personDuplicate, person) => new { PersonId = person.Id, person.LastName, person.FirstName, PersonModifiedDateTime = person.ModifiedDateTime, CreatedByPerson = person.CreatedByPersonAlias.Person.FirstName + " " + person.CreatedByPersonAlias.Person.LastName, personDuplicate.MatchCount, personDuplicate.MaxConfidenceScore }); SortProperty sortProperty = gList.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderByDescending(a => a.MaxConfidenceScore).ThenBy(a => a.LastName).ThenBy(a => a.FirstName); } gList.SetLinqDataSource(qry); gList.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService( rockContext ); var personService = new PersonService( rockContext ); int personId = this.PageParameter( "PersonId" ).AsInteger(); int recordStatusInactiveId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() ).Id; //// select person duplicate records //// list duplicates that aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges. Also, don't include records where both the Person and Duplicate are inactive var qry = personDuplicateService.Queryable() .Where( a => a.PersonAlias.PersonId == personId && !a.IsConfirmedAsNotDuplicate && !a.IgnoreUntilScoreChanges ) .Where( a => a.PersonAlias.Person.RecordStatusValueId != recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId != recordStatusInactiveId ) .Select( s => new { PersonId = s.DuplicatePersonAlias.Person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = s.Id, DuplicatePerson = s.DuplicatePersonAlias.Person, s.ConfidenceScore, IsComparePerson = true } ); double? confidenceScoreLow = GetAttributeValue( "ConfidenceScoreLow" ).AsDoubleOrNull(); if ( confidenceScoreLow.HasValue ) { qry = qry.Where( a => a.ConfidenceScore >= confidenceScoreLow ); } qry = qry.OrderByDescending( a => a.ConfidenceScore ).ThenBy( a => a.DuplicatePerson.LastName ).ThenBy( a => a.DuplicatePerson.FirstName ); var gridList = qry.ToList(); // put the person we are comparing the duplicates to at the top of the list var person = personService.Get( personId ); gridList.Insert( 0, new { PersonId = person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = 0, DuplicatePerson = person, ConfidenceScore = (double?)null, IsComparePerson = false } ); nbNoDuplicatesMessage.Visible = gridList.Count == 1; gList.DataSource = gridList; gList.DataBind(); }
/// <summary> /// Handles the Click event of the btnNotDuplicate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnNotDuplicate_Click( object sender, EventArgs e ) { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService( rockContext ); int personDuplicateId = ( sender as LinkButton ).CommandArgument.AsInteger(); var personDuplicate = personDuplicateService.Get( personDuplicateId ); personDuplicate.IsConfirmedAsNotDuplicate = true; rockContext.SaveChanges(); BindGrid(); }
/// <summary> /// Deletes the family's addresses, phone numbers, photos, viewed records, and people. /// TODO: delete attendance codes for attendance data that's about to be deleted when /// we delete the person record. /// </summary> /// <param name="families">The families.</param> /// <param name="rockContext">The rock context.</param> private void DeleteExistingFamilyData( XElement families, RockContext rockContext ) { PersonService personService = new PersonService( rockContext ); PhoneNumberService phoneNumberService = new PhoneNumberService( rockContext ); PersonViewedService personViewedService = new PersonViewedService( rockContext ); PageViewService pageViewService = new PageViewService( rockContext ); BinaryFileService binaryFileService = new BinaryFileService( rockContext ); PersonAliasService personAliasService = new PersonAliasService( rockContext ); PersonDuplicateService personDuplicateService = new PersonDuplicateService( rockContext ); NoteService noteService = new NoteService( rockContext ); AuthService authService = new AuthService( rockContext ); CommunicationService communicationService = new CommunicationService( rockContext ); CommunicationRecipientService communicationRecipientService = new CommunicationRecipientService( rockContext ); FinancialBatchService financialBatchService = new FinancialBatchService( rockContext ); FinancialTransactionService financialTransactionService = new FinancialTransactionService( rockContext ); PersonPreviousNameService personPreviousNameService = new PersonPreviousNameService( rockContext ); ConnectionRequestService connectionRequestService = new ConnectionRequestService( rockContext ); ConnectionRequestActivityService connectionRequestActivityService = new ConnectionRequestActivityService( rockContext ); // delete the batch data List<int> imageIds = new List<int>(); foreach ( var batch in financialBatchService.Queryable().Where( b => b.Name.StartsWith( "SampleData" ) ) ) { imageIds.AddRange( batch.Transactions.SelectMany( t => t.Images ).Select( i => i.BinaryFileId ).ToList() ); financialTransactionService.DeleteRange( batch.Transactions ); financialBatchService.Delete( batch ); } // delete all transaction images foreach ( var image in binaryFileService.GetByIds( imageIds ) ) { binaryFileService.Delete( image ); } foreach ( var elemFamily in families.Elements( "family" ) ) { Guid guid = elemFamily.Attribute( "guid" ).Value.Trim().AsGuid(); GroupService groupService = new GroupService( rockContext ); Group family = groupService.Get( guid ); if ( family != null ) { var groupMemberService = new GroupMemberService( rockContext ); var members = groupMemberService.GetByGroupId( family.Id, true ); // delete the people records string errorMessage; List<int> photoIds = members.Select( m => m.Person ).Where( p => p.PhotoId != null ).Select( a => (int)a.PhotoId ).ToList(); foreach ( var person in members.Select( m => m.Person ) ) { person.GivingGroup = null; person.GivingGroupId = null; person.PhotoId = null; // delete phone numbers foreach ( var phone in phoneNumberService.GetByPersonId( person.Id ) ) { if ( phone != null ) { phoneNumberService.Delete( phone ); } } // delete communication recipient foreach ( var recipient in communicationRecipientService.Queryable().Where( r => r.PersonAlias.PersonId == person.Id ) ) { communicationRecipientService.Delete( recipient ); } // delete communication foreach ( var communication in communicationService.Queryable().Where( c => c.SenderPersonAliasId == person.PrimaryAlias.Id ) ) { communicationService.Delete( communication ); } // delete person viewed records foreach ( var view in personViewedService.GetByTargetPersonId( person.Id ) ) { personViewedService.Delete( view ); } // delete page viewed records foreach ( var view in pageViewService.GetByPersonId( person.Id ) ) { pageViewService.Delete( view ); } // delete notes created by them or on their record. foreach ( var note in noteService.Queryable().Where ( n => n.CreatedByPersonAlias.PersonId == person.Id || (n.NoteType.EntityTypeId == _personEntityTypeId && n.EntityId == person.Id ) ) ) { noteService.Delete( note ); } // delete previous names on their records foreach ( var previousName in personPreviousNameService.Queryable().Where( r => r.PersonAlias.PersonId == person.Id ) ) { personPreviousNameService.Delete( previousName ); } // delete any GroupMember records they have foreach ( var groupMember in groupMemberService.Queryable().Where( gm => gm.PersonId == person.Id ) ) { groupMemberService.Delete( groupMember ); } //// delete any Authorization data //foreach ( var auth in authService.Queryable().Where( a => a.PersonId == person.Id ) ) //{ // authService.Delete( auth ); //} // delete their aliases foreach ( var alias in personAliasService.Queryable().Where( a => a.PersonId == person.Id ) ) { foreach ( var duplicate in personDuplicateService.Queryable().Where( d => d.DuplicatePersonAliasId == alias.Id ) ) { personDuplicateService.Delete( duplicate ); } personAliasService.Delete( alias ); } // delete any connection requests tied to them foreach ( var request in connectionRequestService.Queryable().Where( r => r.PersonAlias.PersonId == person.Id || r.ConnectorPersonAlias.PersonId == person.Id ) ) { connectionRequestActivityService.DeleteRange( request.ConnectionRequestActivities ); connectionRequestService.Delete( request ); } // Save these changes so the CanDelete passes the check... //rockContext.ChangeTracker.DetectChanges(); rockContext.SaveChanges( disablePrePostProcessing: true ); if ( personService.CanDelete( person, out errorMessage ) ) { personService.Delete( person ); //rockContext.ChangeTracker.DetectChanges(); //rockContext.SaveChanges( disablePrePostProcessing: true ); } else { throw new Exception( string.Format( "Trying to delete {0}, but: {1}", person.FullName, errorMessage ) ); } } //rockContext.ChangeTracker.DetectChanges(); rockContext.SaveChanges( disablePrePostProcessing: true ); // delete all member photos foreach ( var photo in binaryFileService.GetByIds( photoIds ) ) { binaryFileService.Delete( photo ); } DeleteGroupAndMemberData( family, rockContext ); } } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService( rockContext ); var personService = new PersonService( rockContext ); int personId = this.PageParameter( "PersonId" ).AsInteger(); int recordStatusInactiveId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() ).Id; //// select person duplicate records //// list duplicates that aren't confirmed as NotDuplicate. Also, don't include records where both the Person and Duplicate are inactive var qry = personDuplicateService.Queryable() .Where( a => a.PersonAlias.PersonId == personId && !a.IsConfirmedAsNotDuplicate ) .Where( a => a.PersonAlias.Person.RecordStatusValueId != recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId != recordStatusInactiveId ) .Select( s => new { PersonId = s.DuplicatePersonAlias.Person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = s.Id, DuplicatePerson = s.DuplicatePersonAlias.Person, Score = s.Capacity > 0 ? s.Score / ( s.Capacity * .01 ) : (double?)null, IsComparePerson = true } ); qry = qry.OrderByDescending( a => a.Score ).ThenBy( a => a.DuplicatePerson.LastName ).ThenBy( a => a.DuplicatePerson.FirstName ); var gridList = qry.ToList(); // put the person we are comparing the duplicates to at the top of the list var person = personService.Get( personId ); gridList.Insert( 0, new { PersonId = person.Id, // PersonId has to be the key field in the grid for the Merge button to work PersonDuplicateId = 0, DuplicatePerson = person, Score = (double?)null, IsComparePerson = false } ); gList.DataSource = gridList; gList.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService( rockContext ); int recordStatusInactiveId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() ).Id; // list duplicates that aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges. Also, don't include records where both the Person and Duplicate are inactive var personDuplicateQry = personDuplicateService.Queryable() .Where( a => !a.IsConfirmedAsNotDuplicate ) .Where( a => !a.IgnoreUntilScoreChanges ) .Where( a => a.PersonAlias.Person.RecordStatusValueId != recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId != recordStatusInactiveId ); double? confidenceScoreLow = GetAttributeValue( "ConfidenceScoreLow" ).AsDoubleOrNull(); if (confidenceScoreLow.HasValue) { personDuplicateQry = personDuplicateQry.Where( a => a.ConfidenceScore > confidenceScoreLow ); } var groupByQry = personDuplicateQry.GroupBy( a => a.PersonAlias.Person ); var qry = groupByQry.Select( a => new { PersonId = a.Key.Id, LastName = a.Key.LastName, FirstName = a.Key.FirstName, MatchCount = a.Count(), MaxConfidenceScore = a.Max( s => s.ConfidenceScore ), PersonModifiedDateTime = a.Key.ModifiedDateTime, CreatedByPerson = a.Key.CreatedByPersonAlias.Person.FirstName + " " + a.Key.CreatedByPersonAlias.Person.LastName } ); SortProperty sortProperty = gList.SortProperty; if ( sortProperty != null ) { qry = qry.Sort( sortProperty ); } else { qry = qry.OrderByDescending( a => a.MaxConfidenceScore ).ThenBy( a => a.LastName ).ThenBy( a => a.FirstName ); } gList.DataSource = qry.ToList(); gList.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); var personDuplicateService = new PersonDuplicateService( rockContext ); int recordStatusInactiveId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() ).Id; // list duplicates that: // - aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges, // - don't have the PersonAlias and DuplicatePersonAlias records pointing to the same person ( occurs after two people have been merged but before the Calculate Person Duplicates job runs). // - don't include records where both the Person and Duplicate are inactive var personDuplicateQry = personDuplicateService.Queryable() .Where( a => !a.IsConfirmedAsNotDuplicate ) .Where( a => !a.IgnoreUntilScoreChanges ) .Where( a => a.PersonAlias.PersonId != a.DuplicatePersonAlias.PersonId ) .Where( a => !( a.PersonAlias.Person.RecordStatusValueId == recordStatusInactiveId && a.DuplicatePersonAlias.Person.RecordStatusValueId == recordStatusInactiveId ) ); double? confidenceScoreLow = GetAttributeValue( "ConfidenceScoreLow" ).AsDoubleOrNull(); if ( confidenceScoreLow.HasValue ) { personDuplicateQry = personDuplicateQry.Where( a => a.ConfidenceScore > confidenceScoreLow ); } var groupByQry = personDuplicateQry.GroupBy( a => a.PersonAlias.PersonId ); var qryPerson = new PersonService( rockContext ).Queryable(); var qry = groupByQry.Select( a => new { PersonId = a.Key, MatchCount = a.Count(), MaxConfidenceScore = a.Max( s => s.ConfidenceScore ), } ).Join( qryPerson, k1 => k1.PersonId, k2 => k2.Id, ( personDuplicate, person ) => new { PersonId = person.Id, person.LastName, person.FirstName, PersonModifiedDateTime = person.ModifiedDateTime, CreatedByPerson = person.CreatedByPersonAlias.Person.FirstName + " " + person.CreatedByPersonAlias.Person.LastName, personDuplicate.MatchCount, personDuplicate.MaxConfidenceScore } ); SortProperty sortProperty = gList.SortProperty; if ( sortProperty != null ) { qry = qry.Sort( sortProperty ); } else { qry = qry.OrderByDescending( a => a.MaxConfidenceScore ).ThenBy( a => a.LastName ).ThenBy( a => a.FirstName ); } gList.SetLinqDataSource( qry ); gList.DataBind(); }