/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute( Model.WorkflowAction action, Object entity, out List<string> errorMessages ) { var checkInState = GetCheckInState( entity, out errorMessages ); if (checkInState != null) { using ( new Rock.Data.UnitOfWorkScope() ) { var personService = new PersonService(); var memberService = new GroupMemberService(); IQueryable<Person> people = null; if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER ) ) ) { people = personService.GetByPhonePartial( checkInState.CheckIn.SearchValue ); } else if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME ) ) ) { people = personService.GetByFullName( checkInState.CheckIn.SearchValue ); } else { errorMessages.Add( "Invalid Search Type" ); return false; } foreach ( var person in people.ToList() ) { foreach ( var group in person.Members.Where( m => m.Group.GroupType.Guid == new Guid( SystemGuid.GroupType.GROUPTYPE_FAMILY ) ).Select( m => m.Group ).ToList() ) { var family = checkInState.CheckIn.Families.Where( f => f.Group.Id == group.Id ).FirstOrDefault(); if ( family == null ) { family = new CheckInFamily(); family.Group = group.Clone( false ); family.Group.LoadAttributes(); family.Caption = group.ToString(); family.SubCaption = memberService.GetFirstNames( group.Id ).ToList().AsDelimited( ", " ); checkInState.CheckIn.Families.Add( family ); } } } return true; } } errorMessages.Add( "Invalid Check-in State" ); return false; }
private void BindGrid() { string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); if ( !String.IsNullOrWhiteSpace( type ) && !String.IsNullOrWhiteSpace( term ) ) { var rockContext = new RockContext(); var personService = new PersonService( rockContext ); IQueryable<Person> people = null; switch ( type.ToLower() ) { case ( "name" ): { bool allowFirstNameOnly = false; if ( !bool.TryParse( PageParameter( "allowFirstNameOnly" ), out allowFirstNameOnly ) ) { allowFirstNameOnly = false; } people = personService.GetByFullName( term, allowFirstNameOnly, true ); break; } case ( "phone" ): { var phoneService = new PhoneNumberService( rockContext ); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; } case ( "address" ): { var groupMemberService = new GroupMemberService( rockContext ); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; } case ( "email" ): { people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } } SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } var personList = people.ToList(); if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { if ( type.ToLower() == "name" ) { var similiarNames = personService.GetSimiliarNames( term, personList.Select( p => p.Id ).ToList(), true ); if ( similiarNames.Any() ) { var hyperlinks = new List<string>(); foreach ( string name in similiarNames.Distinct() ) { var pageRef = CurrentPageReference; pageRef.Parameters["SearchTerm"] = name; hyperlinks.Add( string.Format( "<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name ) ); } string altNames = string.Join( ", ", hyperlinks ); nbNotice.Text = string.Format( "Other Possible Matches: {0}", altNames ); nbNotice.Visible = true; } } gPeople.DataSource = personList; gPeople.DataBind(); } } }
private void BindGrid() { var birthDateCol = gPeople.ColumnsOfType<DateField>().First( c => c.DataField == "BirthDate" ); birthDateCol.Visible = GetAttributeValue( "ShowBirthdate" ).AsBoolean(); string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); if ( !string.IsNullOrWhiteSpace( type ) && !string.IsNullOrWhiteSpace( term ) ) { term = term.Trim(); type = type.Trim(); var rockContext = new RockContext(); var personService = new PersonService( rockContext ); IQueryable<Person> people = null; switch ( type.ToLower() ) { case ( "name" ): { bool allowFirstNameOnly = false; if ( !bool.TryParse( PageParameter( "allowFirstNameOnly" ), out allowFirstNameOnly ) ) { allowFirstNameOnly = false; } people = personService.GetByFullName( term, allowFirstNameOnly, true ); break; } case ( "phone" ): { var phoneService = new PhoneNumberService( rockContext ); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; } case ( "address" ): { var groupMemberService = new GroupMemberService( rockContext ); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; } case ( "email" ): { people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } } var personIdList = people.Select( p => p.Id ).ToList(); people = personService.Queryable(true).Where( p => personIdList.Contains( p.Id ) ); SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } Guid familyGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ); Guid homeAddressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ); var personList = people.Select( p => new PersonSearchResult { Id = p.Id, FirstName = p.FirstName, NickName = p.NickName, LastName = p.LastName, BirthDate = p.BirthDate, BirthYear = p.BirthYear, BirthMonth = p.BirthMonth, BirthDay = p.BirthDay, ConnectionStatusValueId = p.ConnectionStatusValueId, RecordStatusValueId = p.RecordStatusValueId, RecordTypeValueId = p.RecordTypeValueId, SuffixValueId = p.SuffixValueId, IsDeceased = p.IsDeceased, Email = p.Email, Gender = p.Gender, PhotoId = p.PhotoId, CampusIds = p.Members .Where( m => m.Group.GroupType.Guid.Equals( familyGuid ) && m.Group.CampusId.HasValue ) .Select( m => m.Group.CampusId.Value ) .ToList(), HomeAddresses = p.Members .Where( m => m.Group.GroupType.Guid == familyGuid ) .SelectMany( m => m.Group.GroupLocations ) .Where( gl => gl.GroupLocationTypeValue.Guid.Equals( homeAddressTypeGuid ) ) .Select( gl => gl.Location ) } ).ToList(); if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { if ( type.ToLower() == "name" ) { var similarNames = personService.GetSimilarNames( term, personList.Select( p => p.Id ).ToList(), true ); if ( similarNames.Any() ) { var hyperlinks = new List<string>(); foreach ( string name in similarNames.Distinct() ) { var pageRef = CurrentPageReference; pageRef.Parameters["SearchTerm"] = name; hyperlinks.Add( string.Format( "<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name ) ); } string altNames = string.Join( ", ", hyperlinks ); nbNotice.Text = string.Format( "Other Possible Matches: {0}", altNames ); nbNotice.Visible = true; } } _inactiveStatus = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ); gPeople.EntityTypeId = EntityTypeCache.GetId<Person>(); gPeople.DataSource = personList; gPeople.DataBind(); } } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages ) { var checkInState = GetCheckInState( entity, out errorMessages ); if ( checkInState != null ) { var personService = new PersonService( rockContext ); var memberService = new GroupMemberService( rockContext ); Guid familyGroupTypeGuid = SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid(); if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER ) ) ) { string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric(); var personRecordTypeId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id; // Find the families with any member who has a phone number that contains selected value var familyQry = memberService .Queryable().AsNoTracking() .Where( m => m.Group.GroupType.Guid.Equals( familyGroupTypeGuid ) && m.Person.RecordTypeValueId == personRecordTypeId && m.Person.PhoneNumbers.Any( n => n.Number.Contains( numericPhone ) ) ) .Select( m => m.GroupId ) .Distinct(); int maxResults = GetAttributeValue( action, "MaxResults" ).AsInteger(); if ( maxResults > 0 ) { familyQry = familyQry.Take( maxResults ); } var familyIds = familyQry.ToList(); // Load the family members var familyMembers = memberService .Queryable( "Group,GroupRole,Person" ).AsNoTracking() .Where( m => familyIds.Contains(m.GroupId) ) .ToList(); // Add each family foreach ( int familyId in familyIds ) { // Get each of the members for this family var thisFamilyMembers = familyMembers .Where( m => m.GroupId == familyId && m.Person.NickName != null ) .ToList(); if ( thisFamilyMembers.Any() ) { var group = thisFamilyMembers .Select( m => m.Group ) .FirstOrDefault(); var firstNames = thisFamilyMembers .OrderBy( m => m.GroupRole.Order ) .ThenBy( m => m.Person.BirthYear ) .ThenBy( m => m.Person.BirthMonth ) .ThenBy( m => m.Person.BirthDay ) .ThenBy( m => m.Person.Gender ) .Select( m => m.Person.NickName ) .ToList(); var family = new CheckInFamily(); family.Group = group.Clone( false ); family.Caption = group.ToString(); family.SubCaption = firstNames.AsDelimited( ", " ); checkInState.CheckIn.Families.Add( family ); } } } else if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME ) ) ) { foreach ( var person in personService.GetByFullName( checkInState.CheckIn.SearchValue, false ) ) { foreach ( var group in person.Members.Where( m => m.Group.GroupType.Guid.Equals( familyGroupTypeGuid ) ).Select( m => m.Group ).ToList() ) { var family = checkInState.CheckIn.Families.Where( f => f.Group.Id == group.Id ).FirstOrDefault(); if ( family == null ) { family = new CheckInFamily(); family.Group = group.Clone( false ); family.Group.LoadAttributes( rockContext ); family.Caption = group.ToString(); family.SubCaption = memberService.GetFirstNames( group.Id ).ToList().AsDelimited( ", " ); checkInState.CheckIn.Families.Add( family ); } } } } else { errorMessages.Add( "Invalid Search Type" ); return false; } return true; } errorMessages.Add( "Invalid Check-in State" ); return false; }
/// <summary> /// Checks the database for existing import data. /// returns false if an error occurred /// </summary> private bool LoadExistingData( string importUser ) { //try //{ var lookupContext = new RockContext(); var personService = new PersonService( lookupContext ); var importPerson = personService.GetByFullName( importUser, includeDeceased: false, allowFirstNameOnly: true ).FirstOrDefault(); if ( importPerson == null ) { importPerson = personService.Queryable().FirstOrDefault(); if ( importPerson == null ) { LogException( "CheckExistingImport", "The named import user was not found, and none could be created." ); return false; } } ImportPersonAlias = new PersonAliasService( lookupContext ).Get( importPerson.Id ); PersonEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id; FamilyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id; ReportProgress( 0, "Checking for existing people..." ); ImportedPeople = new GroupService( lookupContext ).GetByGroupTypeId( FamilyGroupTypeId ).Where( n => n.ForeignId != null ).ToList(); CampusList = new CampusService( lookupContext ).Queryable().ToList(); return true; //} //catch ( Exception ex ) //{ // LogException( "CheckExistingImport", ex.ToString() ); // return false; //} }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages ) { var checkInState = GetCheckInState( entity, out errorMessages ); if ( checkInState != null && checkInState.CheckIn.SearchType != null ) { var personService = new PersonService( rockContext ); var memberService = new GroupMemberService( rockContext ); GroupService groupService = new GroupService( rockContext ); PhoneNumberService phoneNumberService = new PhoneNumberService( rockContext ); int familyGroupTypeId = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ).Id; var dvInactive = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() ); if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER ) ) ) { string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric(); var personRecordTypeId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id; // Find the families with any member who has a phone number that contains selected value var familyQry = phoneNumberService.Queryable().AsNoTracking(); if ( checkInState.CheckInType == null || checkInState.CheckInType.PhoneSearchType == PhoneSearchType.EndsWith ) { char[] charArray = numericPhone.ToCharArray(); Array.Reverse( charArray ); familyQry = familyQry.Where( o => o.NumberReversed.StartsWith( new string( charArray ) ) ); } else { familyQry = familyQry.Where( o => o.Number.Contains( numericPhone ) ); } var tmpQry = familyQry.Join( personService.Queryable().AsNoTracking(), o => new { PersonId = o.PersonId, IsDeceased = false, RecordTypeValueId = personRecordTypeId }, p => new { PersonId = p.Id, IsDeceased = p.IsDeceased, RecordTypeValueId = p.RecordTypeValueId.Value }, ( pn, p ) => new { Person = p, PhoneNumber = pn } ) .Join( memberService.Queryable().AsNoTracking(), pn => pn.Person.Id, m => m.PersonId, ( o, m ) => new { PersonNumber = o.PhoneNumber, GroupMember = m } ); var familyIdQry = groupService.Queryable().Where( g => tmpQry.Any( o => o.GroupMember.GroupId == g.Id ) && g.GroupTypeId == familyGroupTypeId ) .Select( g => g.Id ) .Distinct(); int maxResults = checkInState.CheckInType != null ? checkInState.CheckInType.MaxSearchResults : 100; if ( maxResults > 0 ) { familyIdQry = familyIdQry.Take( maxResults ); } var familyIds = familyIdQry.ToList(); // Load the family members var familyMembers = memberService .Queryable( "Group,GroupRole,Person" ).AsNoTracking() .Where( m => familyIds.Contains( m.GroupId ) ) .ToList(); // Add each family foreach ( int familyId in familyIds ) { // Get each of the members for this family var familyMemberQry = familyMembers .Where( m => m.GroupId == familyId && m.Person.NickName != null ); if ( checkInState.CheckInType != null && checkInState.CheckInType.PreventInactivePeopele && dvInactive != null ) { familyMemberQry = familyMemberQry .Where( m => m.Person.RecordStatusValueId != dvInactive.Id ); } var thisFamilyMembers = familyMemberQry.ToList(); if ( thisFamilyMembers.Any() ) { var group = thisFamilyMembers .Select( m => m.Group ) .FirstOrDefault(); var firstNames = thisFamilyMembers .OrderBy( m => m.GroupRole.Order ) .ThenBy( m => m.Person.BirthYear ) .ThenBy( m => m.Person.BirthMonth ) .ThenBy( m => m.Person.BirthDay ) .ThenBy( m => m.Person.Gender ) .Select( m => m.Person.NickName ) .ToList(); var family = new CheckInFamily(); family.Group = group.Clone( false ); family.Caption = group.ToString(); family.SubCaption = firstNames.AsDelimited( ", " ); checkInState.CheckIn.Families.Add( family ); } } } else if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME ) ) ) { var people = personService.GetByFullName( checkInState.CheckIn.SearchValue, false ).AsNoTracking(); if ( checkInState.CheckInType != null && checkInState.CheckInType.PreventInactivePeopele && dvInactive != null ) { people = people.Where( p => p.RecordStatusValueId != dvInactive.Id ); } foreach ( var person in people ) { foreach ( var group in person.Members.Where( m => m.Group.GroupTypeId == familyGroupTypeId ).Select( m => m.Group ).ToList() ) { var family = checkInState.CheckIn.Families.Where( f => f.Group.Id == group.Id ).FirstOrDefault(); if ( family == null ) { family = new CheckInFamily(); family.Group = group.Clone( false ); family.Group.LoadAttributes( rockContext ); family.Caption = group.ToString(); if ( checkInState.CheckInType == null || !checkInState.CheckInType.PreventInactivePeopele ) { family.SubCaption = memberService.GetFirstNames( group.Id ).ToList().AsDelimited( ", " ); } else { family.SubCaption = memberService.GetFirstNames( group.Id, false, false ).ToList().AsDelimited( ", " ); } checkInState.CheckIn.Families.Add( family ); } } } } else { errorMessages.Add( "Invalid Search Type" ); return false; } return true; } errorMessages.Add( "Invalid Check-in State" ); return false; }
/// <summary> /// Binds the person search results grid. /// </summary> private void BindPersonGrid() { var personService = new PersonService( new RockContext() ); var people = personService.Queryable(); if ( !string.IsNullOrEmpty( tbFirstNameSearch.Text ) && !string.IsNullOrEmpty( tbLastNameSearch.Text ) ) { people = personService.GetByFullName( tbFirstNameSearch.Text + " " + tbLastNameSearch.Text, false ); } else if ( !string.IsNullOrEmpty( tbLastNameSearch.Text ) ) { people = people.Where( p => p.LastName.ToLower().StartsWith( tbLastNameSearch.Text ) ); } else if ( !string.IsNullOrEmpty( tbFirstNameSearch.Text ) ) { people = people.Where( p => p.FirstName.ToLower().StartsWith( tbFirstNameSearch.Text ) ); } if ( !string.IsNullOrEmpty( dpDOBSearch.Text ) ) { DateTime searchDate; if ( DateTime.TryParse( dpDOBSearch.Text, out searchDate ) ) { people = people.Where( p => p.BirthYear == searchDate.Year && p.BirthMonth == searchDate.Month && p.BirthDay == searchDate.Day ); } } if ( ddlGenderSearch.SelectedValueAsEnum<Gender>() != 0 ) { var gender = ddlGenderSearch.SelectedValueAsEnum<Gender>(); people = people.Where( p => p.Gender == gender ); } // get the list of people so we can filter by grade and ability level var peopleList = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ).ToList(); var abilityLevelValues = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_ABILITY_LEVEL_TYPE ) ).DefinedValues; peopleList.ForEach( p => p.LoadAttributes() ); if ( ddlAbilitySearch.SelectedIndex != 0 ) { var optionGroup = ddlAbilitySearch.SelectedItem.Attributes["optiongroup"]; if ( optionGroup.Equals( "Grade" ) ) { var grade = ddlAbilitySearch.SelectedValueAsEnum<GradeLevel>(); if ( (int)grade <= 12 ) { peopleList = peopleList.Where( p => p.Grade == (int)grade ).ToList(); } } else if ( optionGroup.Equals( "Ability" ) ) { var abilityLevelGuid = ddlAbilitySearch.SelectedValue; peopleList = peopleList.Where( p => p.Attributes.ContainsKey( "AbilityLevel" ) && p.GetAttributeValue( "AbilityLevel" ) == abilityLevelGuid ).ToList(); } } var matches = peopleList.Select( p => new { p.Id, p.FirstName, p.LastName, p.BirthDate, p.Age, p.Gender, Attribute = p.Grade.HasValue ? ( (GradeLevel) p.Grade ).GetDescription() : abilityLevelValues.Where( dv => dv.Guid.ToString() .Equals( p.GetAttributeValue( "AbilityLevel" ), StringComparison.OrdinalIgnoreCase ) ) .Select( dv => dv.Name ).FirstOrDefault() } ).OrderByDescending( p => p.BirthDate ).ToList(); rGridPersonResults.DataSource = matches; rGridPersonResults.DataBind(); }
/// <summary> /// Transforms the data from the dataset. /// </summary> /// <returns></returns> public override int TransformData( Dictionary<string, string> settings ) { var importUser = settings["ImportUser"]; ReportProgress( 0, "Starting health checks..." ); var rockContext = new RockContext(); var personService = new PersonService( rockContext ); var importPerson = personService.GetByFullName( importUser, allowFirstNameOnly: true ).FirstOrDefault(); if ( importPerson == null ) { importPerson = personService.Queryable().AsNoTracking().FirstOrDefault(); } ImportPersonAliasId = importPerson.PrimaryAliasId; var tableList = DataNodes.Where( n => n.Checked != false ).ToList(); ReportProgress( 0, "Checking for existing attributes..." ); LoadExistingRockData(); ReportProgress( 0, "Checking for existing people..." ); bool isValidImport = ImportedPeople.Any() || tableList.Any( n => n.Name.Equals( "Individual_Household" ) ); var tableDependencies = new List<string>(); tableDependencies.Add( "Batch" ); // needed to attribute contributions properly tableDependencies.Add( "Users" ); // needed for notes, user logins tableDependencies.Add( "Company" ); // needed to attribute any business items tableDependencies.Add( "Individual_Household" ); // needed for just about everything if ( isValidImport ) { ReportProgress( 0, "Checking for table dependencies..." ); // Order tables so non-dependents are imported first if ( tableList.Any( n => tableDependencies.Contains( n.Name ) ) ) { tableList = tableList.OrderByDescending( n => tableDependencies.IndexOf( n.Name ) ).ToList(); } ReportProgress( 0, "Starting data import..." ); var scanner = new DataScanner( Database ); foreach ( var table in tableList ) { switch ( table.Name ) { case "Account": MapBankAccount( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Batch": MapBatch( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Communication": MapCommunication( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Company": MapCompany( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Contribution": MapContribution( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Household_Address": MapFamilyAddress( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Individual_Household": MapPerson( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Notes": MapNotes( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Pledge": MapPledge( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Users": MapUsers( scanner.ScanTable( table.Name ).AsQueryable() ); break; default: break; } } ReportProgress( 100, "Import completed. " ); } else { ReportProgress( 0, "No imported people exist. Please include the Individual_Household table during the import." ); } return 100; // return total number of rows imported? }
/// <summary> /// Checks the database for existing import data. /// returns false if an error occurred /// </summary> private bool LoadExistingData( string importUser ) { var lookupContext = new RockContext(); var personService = new PersonService( lookupContext ); var importPerson = personService.GetByFullName( importUser, includeDeceased: false, allowFirstNameOnly: true ).FirstOrDefault(); if ( importPerson == null ) { importPerson = personService.Queryable().FirstOrDefault(); if ( importPerson == null ) { LogException( "CheckExistingImport", "The named import user was not found, and none could be created." ); return false; } } ImportPersonAliasId = importPerson.PrimaryAliasId; var anonymousGiver = personService.GetByFullName( "Anonymous, Giver", includeDeceased: false, allowFirstNameOnly: true ).FirstOrDefault(); if ( anonymousGiver == null ) { anonymousGiver = personService.Queryable().FirstOrDefault( p => p.Guid.ToString().ToUpper() == "802235DC-3CA5-94B0-4326-AACE71180F48" ); if ( anonymousGiver == null ) { LogException( "CheckExistingImport", "The named Anonymous Giving user was not found, and none could be created." ); return false; } } AnonymousGiverAliasId = anonymousGiver.PrimaryAliasId; PersonEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id; FamilyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id; ReportProgress( 0, "Checking for existing people..." ); // Don't track groups in this context, just use it as a static reference ImportedFamilies = lookupContext.Groups.AsNoTracking() .Where( g => g.GroupTypeId == FamilyGroupTypeId && g.ForeignKey != null ).ToList(); CampusList = new CampusService( lookupContext ).Queryable().ToList(); LoadPersonKeys( lookupContext ); ImportedBatches = new FinancialBatchService( lookupContext ).Queryable().AsNoTracking() .Where( b => b.ForeignId != null ) .ToDictionary( t => ( int )t.ForeignId, t => ( int? )t.Id ); return true; }
/// <summary> /// Transforms the data from the dataset. /// </summary> /// <returns></returns> public override int TransformData( string importUser = null ) { ReportProgress( 0, "Starting import..." ); var personService = new PersonService(); var importPerson = personService.GetByFullName( importUser, includeDeceased: false, allowFirstNameOnly: true ).FirstOrDefault(); ImportPersonAlias = new PersonAliasService().Get( importPerson.Id ); var tableList = TableNodes.Where( n => n.Checked != false ).ToList(); ReportProgress( 0, "Checking for existing attributes..." ); LoadExistingRockData(); ReportProgress( 0, "Checking for table dependencies..." ); bool isValidImport = ImportedPeople.Any() || tableList.Any( n => n.Name.Equals( "Individual_Household" ) ); var tableDependencies = new List<string>(); tableDependencies.Add( "Batch" ); // needed to attribute contributions properly tableDependencies.Add( "Company" ); // needed to attribute any company items tableDependencies.Add( "Individual_Household" ); // needed for just about everything if ( isValidImport ) { // Order tables so non-dependents are imported first if ( tableList.Any( n => tableDependencies.Contains( n.Name ) ) ) { tableList = tableList.OrderByDescending( n => tableDependencies.IndexOf( n.Name ) ).ToList(); } var scanner = new DataScanner( database ); foreach ( var table in tableList ) { if ( !tableDependencies.Contains( table.Name ) ) { switch ( table.Name ) { case "Account": MapBankAccount( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Communication": MapCommunication( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Contribution": MapContribution( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Household_Address": MapFamilyAddress( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Pledge": MapPledge( scanner.ScanTable( table.Name ).AsQueryable() ); break; default: break; } } else { if ( table.Name == "Individual_Household" ) { MapPerson( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "Batch" ) { MapBatch( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "Company" ) { MapCompany( scanner.ScanTable( table.Name ).AsQueryable() ); } } } ReportProgress( 100, "Import completed. " ); } else { ReportProgress( 0, "No imported people exist. Please include the Individual_Household table during the import." ); } return 0; // return total number of rows imported? }
/// <summary> /// Transforms the data from the dataset. /// </summary> /// <returns></returns> public override int TransformData( string importUser = null ) { ReportProgress( 0, "Starting import..." ); var rockContext = new RockContext(); var personService = new PersonService( rockContext ); var importPerson = personService.GetByFullName( importUser, allowFirstNameOnly: true ).FirstOrDefault(); if ( importPerson == null ) { importPerson = personService.Queryable().FirstOrDefault(); } ImportPersonAlias = new PersonAliasService( rockContext ).Get( importPerson.Id ); var tableList = TableNodes.Where( n => n.Checked != false ).ToList(); ReportProgress( 0, "Checking for existing attributes..." ); LoadExistingRockData(); ReportProgress( 0, "Checking for table dependencies..." ); bool isValidImport = ImportedPeople.Any() || tableList.Any( n => n.Name.Equals( "Individual_Household" ) ); var tableDependencies = new List<string>(); tableDependencies.Add( "Batch" ); // needed to attribute contributions properly tableDependencies.Add( "Users" ); // needed for notes, user logins tableDependencies.Add( "Company" ); // needed to attribute any business items tableDependencies.Add( "Individual_Household" ); // needed for just about everything tableDependencies.Add("ActivityMinistry"); // needed for RLC and Attendance tableDependencies.Add("RLC"); // needed for Attendance if ( isValidImport ) { // Order tables so non-dependents are imported first if ( tableList.Any( n => tableDependencies.Contains( n.Name ) ) ) { tableList = tableList.OrderByDescending( n => tableDependencies.IndexOf( n.Name ) ).ToList(); } var scanner = new DataScanner( Database ); foreach ( var table in tableList ) { if ( !tableDependencies.Contains( table.Name ) ) { switch ( table.Name ) { case "Account": MapBankAccount( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Communication": MapCommunication( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Contribution": MapContribution( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Household_Address": MapFamilyAddress( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Notes": MapNotes( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Pledge": MapPledge( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Attribute": MapAttributes( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Groups": MapGroups( scanner.ScanTable( table.Name ).AsQueryable() ); break; //case "ActivityMinistry": // MapActivityMinistry( scanner.ScanTable( table.Name ).AsQueryable() ); // break; //case "RLC": // MapRLC( scanner.ScanTable( table.Name ).AsQueryable() ); // break; case "Attendance": MapAttendance( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "IndividualContactNotes": MapIndividualContactNotes( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "GiftednessProgram": MapGiftednessProgram( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "IndividualGiftedness": MapIndividualGiftedness( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "Authorizations": MapAuthorizations( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "ActivityAssignment": MapActivityAssignment( scanner.ScanTable( table.Name ).AsQueryable() ); break; case "GroupsAttendance": MapGroupsAttendance( scanner.ScanTable( table.Name ).AsQueryable() ); break; default: break; } } else { if ( table.Name == "Batch" ) { MapBatch( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "Company" ) { MapCompany( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "Individual_Household" ) { MapPerson( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "Users" ) { MapUsers( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "ActivityMinistry" ) { MapActivityMinistry( scanner.ScanTable( table.Name ).AsQueryable() ); } else if ( table.Name == "RLC" ) { MapRLC( scanner.ScanTable( table.Name ).AsQueryable() ); } } } ReportProgress( 100, "Import completed. " ); } else { ReportProgress( 0, "No imported people exist. Please include the Individual_Household table during the import." ); } return 0; // return total number of rows imported? }
private void BindGrid() { string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); List<Person> personList = null; if ( !String.IsNullOrWhiteSpace( type ) && !String.IsNullOrWhiteSpace( term ) ) { using ( var uow = new Rock.Data.UnitOfWorkScope() ) { IQueryable<Person> people = null; var personService = new PersonService(); switch ( type.ToLower() ) { case ( "name" ): people = personService.GetByFullName( term, true ); break; case ( "phone" ): var phoneService = new PhoneNumberService(); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; case ( "address" ): var groupMemberService = new GroupMemberService(); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; case ( "email" ): people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } personList = people.ToList(); } } if ( personList != null ) { if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { gPeople.DataSource = personList; gPeople.DataBind(); } } }
/// <summary> /// Checks the database for existing import data. /// returns false if an error occurred /// </summary> private bool LoadExistingData( string importUser ) { var lookupContext = new RockContext(); var personService = new PersonService( lookupContext ); var importPerson = personService.GetByFullName( importUser, includeDeceased: false, allowFirstNameOnly: true ).FirstOrDefault(); if ( importPerson == null ) { importPerson = personService.Queryable().FirstOrDefault(); if ( importPerson == null ) { LogException( "CheckExistingImport", "The named import user was not found, and none could be created." ); return false; } } ImportPersonAlias = new PersonAliasService( lookupContext ).Get( importPerson.Id ); PersonEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id; FamilyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id; ReportProgress( 0, "Checking for existing people..." ); // Don't track groups in this context, just use it as a static reference ImportedPeople = lookupContext.Groups.AsNoTracking().Where( g => g.GroupTypeId == FamilyGroupTypeId && g.ForeignId != null ).ToList(); CampusList = new CampusService( lookupContext ).Queryable().ToList(); return true; }
/// <summary> /// Transforms the data from the dataset. /// </summary> public override int TransformData( Dictionary<string, string> settings ) { var importUser = settings["ImportUser"]; int totalCount = 0; ReportProgress( 0, "Starting health checks..." ); var rockContext = new RockContext(); var personService = new PersonService( rockContext ); var importPerson = personService.GetByFullName( importUser, allowFirstNameOnly: true ).FirstOrDefault(); if ( importPerson == null ) { importPerson = personService.Queryable().AsNoTracking().FirstOrDefault(); } ImportPersonAliasId = importPerson.PrimaryAliasId; ReportProgress( 0, "Checking for existing attributes..." ); LoadRockData( rockContext ); // only import things that the user checked foreach ( var selectedFile in DataNodes.Where( n => n.Checked != false ) ) { var selectedFileType = FileTypes.FirstOrDefault( t => selectedFile.Name.RemoveWhitespace().StartsWith( t.Name.RemoveWhitespace(), StringComparison.InvariantCultureIgnoreCase ) ); if ( selectedFileType == null ) { selectedFileType = FileTypes.FirstOrDefault( f => f.Name == "Default" ); } var archiveFolder = new ZipArchive( new FileStream( selectedFile.Path, FileMode.Open ) ); IBinaryFile worker = IMapAdapterFactory.GetAdapter( selectedFile.Name ); if ( worker != null && selectedFileType != null ) { ReportProgress( 0, string.Format( "Starting {0} file import", selectedFileType.Name ) ); var selectedProvider = StorageProviders.FirstOrDefault( p => selectedFileType.StorageEntityTypeId == p.EntityType.Id ); worker.Map( archiveFolder, selectedFileType, selectedProvider ); totalCount += archiveFolder.Entries.Count; } else { LogException( "Binary File", string.Format( "Unknown File: {0} does not start with the name of a known data map.", selectedFile.Name ) ); } } // Report the final imported count ReportProgress( 100, string.Format( "Completed import: {0:N0} records imported.", totalCount ) ); return totalCount; }