本文整理汇总了C#中Rock.Model.LocationService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# LocationService.Get方法的具体用法?C# LocationService.Get怎么用?C# LocationService.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.LocationService
的用法示例。
在下文中一共展示了LocationService.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatValue
/// <summary>
/// Returns the field's current value(s)
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="value">Information about the value</param>
/// <param name="configurationValues">The configuration values.</param>
/// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
/// <returns></returns>
public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
{
string formattedValue = string.Empty;
if ( !string.IsNullOrWhiteSpace( value ) )
{
var service = new LocationService();
var location = service.Get( new Guid( value ) );
if ( location != null )
{
formattedValue = location.ToString();
}
}
return base.FormatValue( parentControl, formattedValue, null, condensed );
}
示例2: _btnSelect_Click
/// <summary>
/// Handles the Click event of the _btnSelect 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 _btnSelect_Click( object sender, EventArgs e )
{
LocationService locationService = new LocationService( new RockContext() );
var location = locationService.Get( _tbAddress1.Text, _tbAddress2.Text, _tbCity.Text, _ddlState.SelectedItem.Text, _tbZip.Text );
Location = location;
_btnPickerLabel.InnerHtml = string.Format( "<i class='fa fa-user'></i>{0}<b class='fa fa-caret-down pull-right'></b>", this.AddressSummaryText );
}
示例3: AddGroups
/// <summary>
/// Handles adding groups from the given XML element snippet.
/// </summary>
/// <param name="elemGroups">The elem groups.</param>
/// <param name="rockContext">The rock context.</param>
/// <exception cref="System.NotSupportedException"></exception>
private void AddGroups( XElement elemGroups, RockContext rockContext )
{
// Add groups
if ( elemGroups == null )
{
return;
}
GroupService groupService = new GroupService( rockContext );
DefinedTypeCache smallGroupTopicType = DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.SMALL_GROUP_TOPIC.AsGuid() );
// Next create the group along with its members.
foreach ( var elemGroup in elemGroups.Elements( "group" ) )
{
Guid guid = elemGroup.Attribute( "guid" ).Value.Trim().AsGuid();
string type = elemGroup.Attribute( "type" ).Value;
Group group = new Group()
{
Guid = guid,
Name = elemGroup.Attribute( "name" ).Value.Trim(),
IsActive = true,
IsPublic = true
};
// skip any where there is no group type given -- they are invalid entries.
if ( string.IsNullOrEmpty( elemGroup.Attribute( "type" ).Value.Trim() ) )
{
return;
}
int? roleId;
GroupTypeCache groupType;
switch ( elemGroup.Attribute( "type" ).Value.Trim() )
{
case "serving":
groupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SERVING_TEAM.AsGuid() );
group.GroupTypeId = groupType.Id;
roleId = groupType.DefaultGroupRoleId;
break;
case "smallgroup":
groupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SMALL_GROUP.AsGuid() );
group.GroupTypeId = groupType.Id;
roleId = groupType.DefaultGroupRoleId;
break;
default:
throw new NotSupportedException( string.Format( "unknown group type {0}", elemGroup.Attribute( "type" ).Value.Trim() ) );
}
if ( elemGroup.Attribute( "description" ) != null )
{
group.Description = elemGroup.Attribute( "description" ).Value;
}
if ( elemGroup.Attribute( "parentGroupGuid" ) != null )
{
var parentGroup = groupService.Get( elemGroup.Attribute( "parentGroupGuid" ).Value.AsGuid() );
if ( parentGroup != null )
{
group.ParentGroupId = parentGroup.Id;
}
}
// Set the group's meeting location
if ( elemGroup.Attribute( "meetsAtHomeOfFamily" ) != null )
{
int meetingLocationValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_MEETING_LOCATION.AsGuid() ).Id;
var groupLocation = new GroupLocation()
{
IsMappedLocation = false,
IsMailingLocation = false,
GroupLocationTypeValueId = meetingLocationValueId,
LocationId = _familyLocationDictionary[elemGroup.Attribute( "meetsAtHomeOfFamily" ).Value.AsGuid()],
};
// Set the group location's GroupMemberPersonId if given (required?)
if ( elemGroup.Attribute( "meetsAtHomeOfPerson" ) != null )
{
groupLocation.GroupMemberPersonAliasId = _peopleAliasDictionary[elemGroup.Attribute( "meetsAtHomeOfPerson" ).Value.AsGuid()];
}
group.GroupLocations.Add( groupLocation );
}
group.LoadAttributes( rockContext );
// Set the study topic
if ( elemGroup.Attribute( "studyTopic" ) != null )
{
var topic = elemGroup.Attribute( "studyTopic" ).Value;
DefinedValue smallGroupTopicDefinedValue = _smallGroupTopicDefinedType.DefinedValues.FirstOrDefault( a => a.Value == topic );
// add it as new if we didn't find it.
if ( smallGroupTopicDefinedValue == null )
{
//.........这里部分代码省略.........
示例4: LoadFamily
/// <summary>
/// Loads the family data.
/// </summary>
/// <param name="csvData">The CSV data.</param>
private int LoadFamily( CsvDataModel csvData )
{
// Required variables
var lookupContext = new RockContext();
var locationService = new LocationService( lookupContext );
int familyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;
int numImportedFamilies = ImportedPeople.Select( p => p.ForeignId ).Distinct().Count();
int homeLocationTypeId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ) ).Id;
int workLocationTypeId = DefinedValueCache.Read( new Guid( "E071472A-F805-4FC4-917A-D5E3C095C35C" ) ).Id;
var currentFamilyGroup = new Group();
var newFamilyList = new List<Group>();
var newGroupLocations = new Dictionary<GroupLocation, string>();
string currentFamilyId = string.Empty;
int completed = 0;
ReportProgress( 0, string.Format( "Starting family import ({0:N0} already exist).", numImportedFamilies ) );
string[] row;
// Uses a look-ahead enumerator: this call will move to the next record immediately
while ( ( row = csvData.Database.FirstOrDefault() ) != null )
{
string rowFamilyId = row[FamilyId];
string rowFamilyName = row[FamilyName];
if ( !string.IsNullOrWhiteSpace( rowFamilyId ) && rowFamilyId != currentFamilyGroup.ForeignId )
{
currentFamilyGroup = ImportedPeople.FirstOrDefault( p => p.ForeignId == rowFamilyId );
if ( currentFamilyGroup == null )
{
currentFamilyGroup = new Group();
currentFamilyGroup.ForeignId = rowFamilyId;
currentFamilyGroup.Name = row[FamilyName];
currentFamilyGroup.CreatedByPersonAliasId = ImportPersonAlias.Id;
currentFamilyGroup.GroupTypeId = familyGroupTypeId;
newFamilyList.Add( currentFamilyGroup );
}
// Set the family campus
string campusName = row[Campus];
if ( !string.IsNullOrWhiteSpace( campusName ) )
{
var familyCampus = CampusList.Where( c => c.Name.StartsWith( campusName ) || c.ShortCode.StartsWith( campusName ) ).FirstOrDefault();
if ( familyCampus == null )
{
familyCampus = new Campus();
familyCampus.IsSystem = false;
familyCampus.Name = campusName;
lookupContext.Campuses.Add( familyCampus );
lookupContext.SaveChanges( true );
}
// This won't assign a campus if the family already exists because the context doesn't get saved
currentFamilyGroup.CampusId = familyCampus.Id;
}
// Add the family addresses since they exist in this file
string famAddress = row[Address];
string famAddress2 = row[Address2];
string famCity = row[City];
string famState = row[State];
string famZip = row[Zip];
string famCountry = row[Country];
// Use the core Rock location service to add or lookup an address
Location primaryAddress = locationService.Get( famAddress, famAddress2, famCity, famState, famZip, famCountry );
if ( primaryAddress != null )
{
primaryAddress.Name = currentFamilyGroup.Name + " Home";
var primaryLocation = new GroupLocation();
primaryLocation.LocationId = primaryAddress.Id;
primaryLocation.IsMailingLocation = true;
primaryLocation.IsMappedLocation = true;
primaryLocation.GroupLocationTypeValueId = homeLocationTypeId;
newGroupLocations.Add( primaryLocation, rowFamilyId );
}
string famSecondAddress = row[SecondaryAddress];
string famSecondAddress2 = row[SecondaryAddress2];
string famSecondCity = row[SecondaryCity];
string famSecondState = row[SecondaryState];
string famSecondZip = row[SecondaryZip];
string famSecondCountry = row[SecondaryCountry];
Location secondaryAddress = locationService.Get( famSecondAddress, famSecondAddress2, famSecondCity, famSecondState, famSecondZip, famSecondCountry );
if ( secondaryAddress != null )
{
secondaryAddress.Name = currentFamilyGroup.Name + " Work";
var secondaryLocation = new GroupLocation();
secondaryLocation.LocationId = primaryAddress.Id;
secondaryLocation.IsMailingLocation = true;
//.........这里部分代码省略.........
示例5: btnStandardize_Click
/// <summary>
/// Handles the Click event of the btnStandardize 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 btnStandardize_Click( object sender, EventArgs e )
{
int locationId = hfLocationId.Value.AsInteger();
var rockContext = new RockContext();
var service = new LocationService( rockContext );
var location = service.Get( locationId );
if (location == null)
{
// if they are adding a new named location, there won't be a location record yet, so just make a new one for the verification
location = new Location();
}
acAddress.GetValues( location );
service.Verify( location, true );
acAddress.SetValues( location );
geopPoint.SetValue( location.GeoPoint );
lStandardizationUpdate.Text = String.Format( "<div class='alert alert-info'>Standardization Result: {0}<br/>Geocoding Result: {1}</div>",
location.StandardizeAttemptedResult.IfEmpty( "No Result" ),
location.GeocodeAttemptedResult.IfEmpty( "No Result" ) );
}
示例6: btnEdit_Click
/// <summary>
/// Handles the Click event of the btnEdit 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 btnEdit_Click( object sender, EventArgs e )
{
LocationService locationService = new LocationService( new RockContext() );
Location location = locationService.Get( int.Parse( hfLocationId.Value ) );
ShowEditDetails( location );
}
示例7: btnCancel_Click
/// <summary>
/// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e )
{
if ( hfLocationId.Value.Equals( "0" ) )
{
int? parentLocationId = PageParameter( "ParentLocationId" ).AsIntegerOrNull();
if ( parentLocationId.HasValue )
{
// Cancelling on Add, and we know the parentLocationId, so we are probably in treeview mode, so navigate to the current page
var qryParams = new Dictionary<string, string>();
qryParams["LocationId"] = parentLocationId.ToString();
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
NavigateToPage( RockPage.Guid, qryParams );
}
else
{
// Cancelling on Add. Return to Grid
NavigateToParentPage();
}
}
else
{
// Cancelling on Edit. Return to Details
LocationService locationService = new LocationService( new RockContext() );
Location location = locationService.Get( int.Parse( hfLocationId.Value ) );
ShowReadonlyDetails( location );
}
}
示例8: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
protected void BindGrid()
{
AddScheduleColumns();
var rockContext = new RockContext();
var groupLocationService = new GroupLocationService( rockContext );
var groupTypeService = new GroupTypeService( rockContext );
var groupService = new GroupService( rockContext );
IEnumerable<GroupTypePath> groupPaths = new List<GroupTypePath>();
var groupLocationQry = groupLocationService.Queryable();
List<int> currentAndDescendantGroupTypeIds = new List<int>();
var currentGroupTypeIds = this.CurrentGroupTypeIds.ToList();
currentAndDescendantGroupTypeIds.AddRange( currentGroupTypeIds );
foreach ( var templateGroupType in groupTypeService.Queryable().Where( a => currentGroupTypeIds.Contains( a.Id ) ) )
{
foreach ( var childGroupType in groupTypeService.GetChildGroupTypes( templateGroupType.Id ) )
{
currentAndDescendantGroupTypeIds.Add( childGroupType.Id );
currentAndDescendantGroupTypeIds.AddRange( groupTypeService.GetAllAssociatedDescendents( childGroupType.Id ).Select( a => a.Id ).ToList() );
}
}
groupLocationQry = groupLocationQry.Where( a => currentAndDescendantGroupTypeIds.Contains( a.Group.GroupTypeId ) );
groupLocationQry = groupLocationQry.OrderBy( a => a.Group.Name ).ThenBy( a => a.Location.Name );
List<int> currentDeviceLocationIdList = this.GetGroupTypesLocations( rockContext ).Select( a => a.Id ).Distinct().ToList();
var qryList = groupLocationQry
.Where( a => currentDeviceLocationIdList.Contains( a.LocationId ) )
.Select( a =>
new
{
GroupLocationId = a.Id,
a.Location,
GroupId = a.GroupId,
GroupName = a.Group.Name,
ScheduleIdList = a.Schedules.Select( s => s.Id ),
GroupTypeId = a.Group.GroupTypeId
} ).ToList();
var locationService = new LocationService( rockContext );
// put stuff in a datatable so we can dynamically have columns for each Schedule
DataTable dataTable = new DataTable();
dataTable.Columns.Add( "GroupLocationId" );
dataTable.Columns.Add( "GroupId" );
dataTable.Columns.Add( "GroupName" );
dataTable.Columns.Add( "GroupPath" );
dataTable.Columns.Add( "LocationName" );
dataTable.Columns.Add( "LocationPath" );
foreach ( var field in gGroupLocationSchedule.Columns.OfType<CheckBoxEditableField>() )
{
dataTable.Columns.Add( field.DataField, typeof( bool ) );
}
var locationPaths = new Dictionary<int, string>();
foreach ( var row in qryList )
{
DataRow dataRow = dataTable.NewRow();
dataRow["GroupLocationId"] = row.GroupLocationId;
dataRow["GroupName"] = groupService.GroupAncestorPathName( row.GroupId );
dataRow["GroupPath"] = groupPaths.Where( gt => gt.GroupTypeId == row.GroupTypeId ).Select( gt => gt.Path ).FirstOrDefault();
dataRow["LocationName"] = row.Location.Name;
if ( row.Location.ParentLocationId.HasValue )
{
int locationId = row.Location.ParentLocationId.Value;
if ( !locationPaths.ContainsKey( locationId ) )
{
var locationNames = new List<string>();
var parentLocation = locationService.Get( locationId );
while ( parentLocation != null )
{
locationNames.Add( parentLocation.Name );
parentLocation = parentLocation.ParentLocation;
}
if ( locationNames.Any() )
{
locationNames.Reverse();
locationPaths.Add( locationId, locationNames.AsDelimited( " > " ) );
}
else
{
locationPaths.Add( locationId, string.Empty );
}
}
dataRow["LocationPath"] = locationPaths[locationId];
}
//.........这里部分代码省略.........
示例9: AddGroups
/// <summary>
/// Handles adding groups from the given XML element snippet.
/// </summary>
/// <param name="elemGroups">The elem groups.</param>
/// <param name="rockContext">The rock context.</param>
/// <exception cref="System.NotSupportedException"></exception>
private void AddGroups( XElement elemGroups, RockContext rockContext )
{
// Add groups
if ( elemGroups == null )
{
return;
}
GroupService groupService = new GroupService( rockContext );
// Next create the group along with its members.
foreach ( var elemGroup in elemGroups.Elements( "group" ) )
{
Guid guid = elemGroup.Attribute( "guid" ).Value.Trim().AsGuid();
string type = elemGroup.Attribute( "type" ).Value;
Group group = new Group()
{
Guid = guid,
Name = elemGroup.Attribute( "name" ).Value.Trim()
};
// skip any where there is no group type given -- they are invalid entries.
if ( string.IsNullOrEmpty( elemGroup.Attribute( "type" ).Value.Trim() ) )
{
return;
}
int? roleId;
GroupTypeCache groupType;
switch ( elemGroup.Attribute( "type" ).Value.Trim() )
{
case "serving":
groupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SERVING_TEAM.AsGuid() );
group.GroupTypeId = groupType.Id;
roleId = groupType.DefaultGroupRoleId;
break;
case "smallgroup":
groupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SMALL_GROUP.AsGuid() );
group.GroupTypeId = groupType.Id;
roleId = groupType.DefaultGroupRoleId;
break;
default:
throw new NotSupportedException( string.Format( "unknown group type {0}", elemGroup.Attribute( "type" ).Value.Trim() ) );
}
if ( elemGroup.Attribute( "description" ) != null )
{
group.Description = elemGroup.Attribute( "description" ).Value;
}
if ( elemGroup.Attribute( "parentGroupGuid" ) != null )
{
var parentGroup = groupService.Get( elemGroup.Attribute( "parentGroupGuid" ).Value.AsGuid() );
group.ParentGroupId = parentGroup.Id;
}
// Set the group's meeting location
if ( elemGroup.Attribute( "meetsAtHomeOfFamily" ) != null )
{
int meetingLocationValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_MEETING_LOCATION.AsGuid() ).Id;
var groupLocation = new GroupLocation()
{
IsMappedLocation = false,
IsMailingLocation = false,
GroupLocationTypeValueId = meetingLocationValueId,
LocationId = _familyLocationDictionary[elemGroup.Attribute( "meetsAtHomeOfFamily" ).Value.AsGuid()],
};
// Set the group location's GroupMemberPersonId if given (required?)
if ( elemGroup.Attribute( "meetsAtHomeOfPerson" ) != null )
{
groupLocation.GroupMemberPersonId = _peopleDictionary[elemGroup.Attribute( "meetsAtHomeOfPerson" ).Value.AsGuid()];
}
group.GroupLocations.Add( groupLocation );
}
group.LoadAttributes( rockContext );
// Set the study topic
if ( elemGroup.Attribute( "studyTopic" ) != null )
{
group.SetAttributeValue( "StudyTopic", elemGroup.Attribute( "studyTopic" ).Value );
}
// Set the meeting time
if ( elemGroup.Attribute( "meetingTime" ) != null )
{
group.SetAttributeValue( "MeetingTime", elemGroup.Attribute( "meetingTime" ).Value );
}
// Add each person as a member
foreach ( var elemPerson in elemGroup.Elements( "person" ) )
{
//.........这里部分代码省略.........
示例10: rptrAddresses_ItemCommand
/// <summary>
/// Handles the ItemCommand event of the rptrAddresses control.
/// </summary>
/// <param name="source">The source of the event.</param>
/// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param>
protected void rptrAddresses_ItemCommand( object source, RepeaterCommandEventArgs e )
{
int locationId = int.MinValue;
if ( int.TryParse( e.CommandArgument.ToString(), out locationId ) )
{
using ( var rockContext = new RockContext() )
{
var service = new LocationService( rockContext );
var location = service.Get( locationId );
if ( location != null )
{
switch ( e.CommandName )
{
case "verify":
{
service.Verify( location, true );
rockContext.SaveChanges();
break;
}
case "settings":
{
NavigateToLinkedPage( "LocationDetailPage",
new Dictionary<string, string> { { "LocationId", location.Id.ToString() }, { "PersonId", Person.Id.ToString() } } );
break;
}
}
}
}
}
BindGroups();
}
示例11: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
{
Location location;
var rockContext = new RockContext();
LocationService locationService = new LocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
int locationId = int.Parse( hfLocationId.Value );
if ( locationId == 0 )
{
location = new Location();
location.Name = string.Empty;
}
else
{
location = locationService.Get( locationId );
}
location.Name = tbName.Text;
location.IsActive = cbIsActive.Checked;
location.LocationTypeValueId = ddlLocationType.SelectedValueAsId();
if ( gpParentLocation != null && gpParentLocation.Location != null )
{
location.ParentLocationId = gpParentLocation.Location.Id;
}
else
{
location.ParentLocationId = null;
}
location.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
var addrLocation = locapAddress.Location;
if ( addrLocation != null )
{
location.Street1 = addrLocation.Street1;
location.Street2 = addrLocation.Street2;
location.City = addrLocation.City;
location.State = addrLocation.State;
location.Zip = addrLocation.Zip;
}
location.GeoPoint = geopPoint.SelectedValue;
if ( geopPoint.SelectedValue != null )
{
location.IsGeoPointLocked = true;
}
location.GeoFence = geopFence.SelectedValue;
location.IsGeoPointLocked = cbGeoPointLocked.Checked;
location.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributeEdits, location );
if ( !Page.IsValid )
{
return;
}
if ( !location.IsValid )
{
// Controls will render the error messages
return;
}
RockTransactionScope.WrapTransaction( () =>
{
if ( location.Id.Equals( 0 ) )
{
locationService.Add( location );
}
rockContext.SaveChanges();
location.SaveAttributeValues( rockContext );
} );
var qryParams = new Dictionary<string, string>();
qryParams["LocationId"] = location.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
示例12: MapFamilyAddress
/// <summary>
/// Maps the family address.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapFamilyAddress( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
var locationService = new LocationService( lookupContext );
List<GroupMember> familyGroupMemberList = new GroupMemberService( lookupContext ).Queryable().AsNoTracking()
.Where( gm => gm.Group.GroupType.Guid == new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ) ).ToList();
var groupLocationDefinedType = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.GROUP_LOCATION_TYPE ), lookupContext );
int homeGroupLocationTypeId = groupLocationDefinedType.DefinedValues
.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ) ).Id;
int workGroupLocationTypeId = groupLocationDefinedType.DefinedValues
.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_WORK ) ).Id;
int previousGroupLocationTypeId = groupLocationDefinedType.DefinedValues
.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS ) ).Id;
string otherGroupLocationName = "Other (Imported)";
int? otherGroupLocationTypeId = groupLocationDefinedType.DefinedValues
.Where( dv => dv.TypeName == otherGroupLocationName )
.Select( dv => (int?)dv.Id ).FirstOrDefault();
if ( otherGroupLocationTypeId == null )
{
var otherGroupLocationType = new DefinedValue();
otherGroupLocationType.Value = otherGroupLocationName;
otherGroupLocationType.DefinedTypeId = groupLocationDefinedType.Id;
otherGroupLocationType.IsSystem = false;
otherGroupLocationType.Order = 0;
lookupContext.DefinedValues.Add( otherGroupLocationType );
lookupContext.SaveChanges( DisableAuditing );
otherGroupLocationTypeId = otherGroupLocationType.Id;
}
var newGroupLocations = new List<GroupLocation>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying address import ({0:N0} found).", totalRows ) );
foreach ( var row in tableData.Where( r => r != null ) )
{
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
var personKeys = GetPersonKeys( individualId, householdId, includeVisitors: false );
if ( personKeys != null )
{
var familyGroup = familyGroupMemberList.Where( gm => gm.PersonId == personKeys.PersonId )
.Select( gm => gm.Group ).FirstOrDefault();
if ( familyGroup != null )
{
var groupLocation = new GroupLocation();
string street1 = row["Address_1"] as string;
string street2 = row["Address_2"] as string;
string city = row["City"] as string;
string state = row["State"] as string;
string country = row["country"] as string; // NOT A TYPO: F1 has property in lower-case
string zip = row["Postal_Code"] as string ?? string.Empty;
// restrict zip to 5 places to prevent duplicates
Location familyAddress = locationService.Get( street1, street2, city, state, zip.Left( 5 ), country, verifyLocation: false );
if ( familyAddress != null )
{
familyAddress.CreatedByPersonAliasId = ImportPersonAliasId;
familyAddress.Name = familyGroup.Name;
familyAddress.IsActive = true;
groupLocation.GroupId = familyGroup.Id;
groupLocation.LocationId = familyAddress.Id;
groupLocation.IsMailingLocation = true;
groupLocation.IsMappedLocation = true;
string addressType = row["Address_Type"].ToString().ToLower();
if ( addressType.Equals( "primary" ) )
{
groupLocation.GroupLocationTypeValueId = homeGroupLocationTypeId;
}
else if ( addressType.Equals( "business" ) || addressType.ToLower().Equals( "org" ) )
{
groupLocation.GroupLocationTypeValueId = workGroupLocationTypeId;
}
else if ( addressType.Equals( "previous" ) )
{
groupLocation.GroupLocationTypeValueId = previousGroupLocationTypeId;
}
else if ( !string.IsNullOrEmpty( addressType ) )
{
// look for existing group location types, otherwise mark as imported
var customTypeId = groupLocationDefinedType.DefinedValues.Where( dv => dv.Value.ToLower().Equals( addressType ) )
.Select( dv => (int?)dv.Id ).FirstOrDefault();
groupLocation.GroupLocationTypeValueId = customTypeId ?? otherGroupLocationTypeId;
//.........这里部分代码省略.........
示例13: rptrAddresses_ItemCommand
void rptrAddresses_ItemCommand( object source, RepeaterCommandEventArgs e )
{
int locationId = int.MinValue;
if ( int.TryParse( e.CommandArgument.ToString(), out locationId ) )
{
var service = new LocationService();
var location = service.Get( locationId );
switch ( e.CommandName )
{
case "geocode":
service.Geocode( location, CurrentPersonId );
break;
case "standardize":
service.Standardize( location, CurrentPersonId );
break;
}
service.Save( location, CurrentPersonId );
}
BindFamilies();
}
示例14: GetEditValue
/// <summary>
/// Reads new values entered by the user for the field ( as Guid )
/// </summary>
/// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
/// <param name="configurationValues">The configuration values.</param>
/// <returns></returns>
public override string GetEditValue( Control control, Dictionary<string, ConfigurationValue> configurationValues )
{
var addressControl = control as AddressControl;
var locationService = new LocationService( new RockContext() );
string result = null;
if ( addressControl != null )
{
var guid = Guid.Empty;
var location = locationService.Get( addressControl.Street1, addressControl.Street2, addressControl.City, addressControl.State, addressControl.PostalCode, addressControl.Country );
if ( location != null )
{
guid = location.Guid;
}
result = guid.ToString();
}
return result;
}
示例15: FindDuplicates
public bool FindDuplicates()
{
Duplicates = new Dictionary<Guid, List<Person>>();
var rockContext = new RockContext();
var locationService = new LocationService( rockContext );
var groupService = new GroupService( rockContext );
var personService = new PersonService( rockContext );
// Find any other group members (any group) that have same location
var othersAtAddress = new List<int>();
string locationKey = GetLocationKey();
if ( !string.IsNullOrWhiteSpace(locationKey) && _verifiedLocations.ContainsKey( locationKey))
{
int? locationId = _verifiedLocations[locationKey];
if ( locationId.HasValue )
{
var location = locationService.Get( locationId.Value );
if ( location != null )
{
othersAtAddress = groupService
.Queryable().AsNoTracking()
.Where( g =>
g.GroupTypeId == _locationType.Id &&
g.GroupLocations.Any( l => l.LocationId == location.Id ) )
.SelectMany( g => g.Members )
.Select( m => m.PersonId )
.ToList();
}
}
}
foreach ( var person in GroupMembers
.Where( m =>
m.Person != null &&
m.Person.FirstName != "" )
.Select( m => m.Person ) )
{
bool otherCriteria = false;
var personQry = personService
.Queryable().AsNoTracking()
.Where( p =>
p.FirstName == person.FirstName ||
p.NickName == person.FirstName );
if ( othersAtAddress.Any() )
{
personQry = personQry
.Where( p => othersAtAddress.Contains( p.Id ) );
}
if ( person.BirthDate.HasValue )
{
otherCriteria = true;
personQry = personQry
.Where( p =>
p.BirthDate.HasValue &&
p.BirthDate.Value == person.BirthDate.Value );
}
if ( _homePhone != null )
{
var homePhoneNumber = person.PhoneNumbers.Where( p => p.NumberTypeValueId == _homePhone.Id ).FirstOrDefault();
if ( homePhoneNumber != null )
{
otherCriteria = true;
personQry = personQry
.Where( p =>
p.PhoneNumbers.Any( n =>
n.NumberTypeValueId == _homePhone.Id &&
n.Number == homePhoneNumber.Number ) );
}
}
if ( _cellPhone != null )
{
var cellPhoneNumber = person.PhoneNumbers.Where( p => p.NumberTypeValueId == _cellPhone.Id ).FirstOrDefault();
if ( cellPhoneNumber != null )
{
otherCriteria = true;
personQry = personQry
.Where( p =>
p.PhoneNumbers.Any( n =>
n.NumberTypeValueId == _cellPhone.Id &&
n.Number == cellPhoneNumber.Number ) );
}
}
if ( !string.IsNullOrWhiteSpace( person.Email ) )
{
otherCriteria = true;
personQry = personQry
.Where( p => p.Email == person.Email );
}
var dups = new List<Person>();
if ( otherCriteria )
{
// If a birthday, email, phone, or address was entered, find anyone with same info and same first name
//.........这里部分代码省略.........