本文整理汇总了C#中Rock.Model.GroupService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.Get方法的具体用法?C# GroupService.Get怎么用?C# GroupService.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: bbtnVerify_Click
/// <summary>
/// Marks the selected people/photos as verified by setting their group member status Active.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void bbtnVerify_Click( object sender, EventArgs e )
{
nbMessage.Visible = true;
int count = 0;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
Group group = groupService.Get( Rock.SystemGuid.Group.GROUP_PHOTO_REQUEST.AsGuid() );
GroupMember groupMember = null;
var itemsSelected = new List<int>();
gList.SelectedKeys.ToList().ForEach( i => itemsSelected.Add( i.ToString().AsInteger() ) );
if ( itemsSelected.Any() )
{
foreach ( int currentRowsPersonId in itemsSelected )
{
groupMember = group.Members.Where( m => m.PersonId == currentRowsPersonId ).FirstOrDefault();
if ( groupMember != null )
{
count++;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
}
}
}
if ( count > 0 )
{
nbMessage.NotificationBoxType = NotificationBoxType.Success;
nbMessage.Text = string.Format( "Verified {0} photo{1}.", count, count > 1 ? "s" : "" );
}
else
{
nbMessage.NotificationBoxType = NotificationBoxType.Warning;
nbMessage.Text = "No photos selected.";
}
rockContext.SaveChanges();
_photoRequestGroup = group;
BindGrid();
}
示例2: bbtnVerify_Click
/// <summary>
/// Marks the selected people/photos as verified by setting their group member status Active.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void bbtnVerify_Click( object sender, EventArgs e )
{
nbMessage.Visible = true;
int count = 0;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
Group group = groupService.Get( Rock.SystemGuid.Group.GROUP_PHOTO_REQUEST.AsGuid() );
GroupMember groupMember = null;
foreach ( GridViewRow row in gList.Rows )
{
var cb = row.FindControl( "cbSelected" ) as CheckBox;
if ( cb != null && cb.Checked )
{
int currentRowsPersonId = (int)gList.DataKeys[row.RowIndex].Value;
groupMember = group.Members.Where( m => m.PersonId == currentRowsPersonId ).FirstOrDefault();
if ( groupMember != null )
{
count++;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
}
}
}
if ( count > 0 )
{
nbMessage.NotificationBoxType = NotificationBoxType.Success;
nbMessage.Text = string.Format( "Verified {0} photo{1}.", count, count > 1 ? "s" : "" );
}
else
{
nbMessage.NotificationBoxType = NotificationBoxType.Warning;
nbMessage.Text = "No changes were made.";
}
rockContext.SaveChanges();
_photoRequestGroup = group;
BindGrid();
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Guid? rootGroupGuid = GetAttributeValue("RootGroup").AsGuidOrNull();
GroupService gs = new GroupService(new RockContext());
if (rootGroupGuid != null)
{
var staffGroup = gs.Get(rootGroupGuid.Value);
var groupMembers = staffGroup.Members.OrderByDescending(g => g.GroupMemberStatus).Select(m => m.Person).OrderBy(m => m.LastName).ThenBy(m => m.FirstName).ToList();
var groupName = staffGroup.Name.ToString();
this.lblGroupName.Text = groupName;
var people = new List<PersonData>();
foreach (var person in groupMembers)
{
person.LoadAttributes();
people.Add(new PersonData { Name = person.FullName, PhotoUrl = person.PhotoUrl, Position = person.GetAttributeValue("Position") });
}
this.rptStaff.DataSource = people;
this.rptStaff.DataBind();
}
}
示例4: AddRelationships
//.........这里部分代码省略.........
break;
case "invited-by":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED_BY.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "previous-spouse":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_PREVIOUS_SPOUSE.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "sibling":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_SIBLING.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "parent":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_PARENT.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "child":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CHILD.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "related":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_IMPLIED_RELATIONSHIPS_RELATED.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
default:
//// throw new NotSupportedException( string.Format( "unknown relationship type {0}", elemRelationship.Attribute( "has" ).Value ) );
// just skip unknown relationship types
continue;
}
// find the person's KnownRelationship "owner" group
var knownRelationshipGroup = memberService.Queryable()
.Where( m =>
m.PersonId == ownerPersonId &&
m.GroupRole.Guid == ownerRoleGuid )
.Select( m => m.Group )
.FirstOrDefault();
// create it if it does not yet exist
if ( knownRelationshipGroup == null )
{
var ownerRole = new GroupTypeRoleService( rockContext ).Get( ownerRoleGuid );
if ( ownerRole != null && ownerRole.GroupTypeId.HasValue )
{
var ownerGroupMember = new GroupMember();
ownerGroupMember.PersonId = ownerPersonId;
ownerGroupMember.GroupRoleId = ownerRole.Id;
knownRelationshipGroup = new Group();
knownRelationshipGroup.Name = ownerRole.GroupType.Name;
knownRelationshipGroup.GroupTypeId = ownerRole.GroupTypeId.Value;
knownRelationshipGroup.Members.Add( ownerGroupMember );
var groupService = new GroupService( rockContext );
groupService.Add( knownRelationshipGroup );
//rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( disablePrePostProcessing: true );
knownRelationshipGroup = groupService.Get( knownRelationshipGroup.Id );
}
}
// Now find (and add if not found) the forPerson as a member with the "has" role-type
var groupMember = memberService.Queryable()
.Where( m =>
m.GroupId == knownRelationshipGroup.Id &&
m.PersonId == forPersonId &&
m.GroupRoleId == roleId )
.FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember()
{
GroupId = knownRelationshipGroup.Id,
PersonId = forPersonId,
GroupRoleId = roleId,
};
rockContext.GroupMembers.Add( groupMember );
}
// Now create thee inverse relationship.
//
// (NOTE: Don't panic if your VS tooling complains that there is
// an unused variable here. There is no need to do anything with the
// inverseGroupMember relationship because it was already added to the
// context. All we have to do below is save the changes to the context
// when we're ready.)
var inverseGroupMember = memberService.GetInverseRelationship( groupMember, createGroup: true );
}
}
示例5: 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 )
{
//.........这里部分代码省略.........
示例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 )
{
GroupService groupService = new GroupService();
Group group = groupService.Get( int.Parse( hfGroupId.Value ) );
ShowEditDetails( group );
}
示例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 ( hfGroupId.Value.Equals( "0" ) )
{
if ( RockPage.Layout.FileName.Equals( "TwoColumnLeft" ) )
{
// Cancelling on Add. Return to tree view with parent category selected
var qryParams = new Dictionary<string, string>();
string parentGroupId = PageParameter( "parentGroupId" );
if ( !string.IsNullOrWhiteSpace( parentGroupId ) )
{
qryParams["groupId"] = parentGroupId;
}
NavigateToPage( RockPage.Guid, qryParams );
}
else
{
// Cancelling on Add. Return to Grid
NavigateToParentPage();
}
}
else
{
// Cancelling on Edit. Return to Details
GroupService groupService = new GroupService();
Group group = groupService.Get( int.Parse( hfGroupId.Value ) );
ShowReadonlyDetails( group );
}
}
示例8: rGrid_Delete
/// <summary>
/// Handles the Delete event to delete the photo.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
protected void rGrid_Delete( object sender, RowEventArgs e )
{
RockContext rockContext = new RockContext();
int currentRowsPersonId = (int)e.RowKeyValues["PersonId"];
GroupService groupService = new GroupService( rockContext );
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
// Set their group member record to Active
Group group = groupService.Get( Rock.SystemGuid.Group.GROUP_PHOTO_REQUEST.AsGuid() );
GroupMember groupMember = group.Members.Where( m => m.PersonId == currentRowsPersonId ).FirstOrDefault();
if ( groupMember != null )
{
binaryFileService.Delete( groupMember.Person.Photo );
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
groupMember.Person.Photo = null;
groupMember.Person.PhotoId = null;
rockContext.SaveChanges();
_photoRequestGroup = group;
BindGrid();
}
}
示例9: btnSaveGroup_Click
/// <summary>
/// Handles the Click event of the btnSaveGroup 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 btnSaveGroup_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
Group group = groupService.Get( _groupId );
if ( group != null && group.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
{
group.Name = tbName.Text;
group.Description = tbDescription.Text;
group.IsActive = cbIsActive.Checked;
if ( pnlSchedule.Visible )
{
if ( group.Schedule == null )
{
group.Schedule = new Schedule();
group.Schedule.iCalendarContent = null;
}
group.Schedule.WeeklyDayOfWeek = dowWeekly.SelectedDayOfWeek;
group.Schedule.WeeklyTimeOfDay = timeWeekly.SelectedTime;
}
// set attributes
group.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributes, group );
// configure locations
if ( GetAttributeValue( "EnableLocationEdit" ).AsBoolean() )
{
// get selected location
Location location = null;
int? memberPersonAliasId = null;
if ( LocationTypeTab.Equals( MEMBER_LOCATION_TAB_TITLE ) )
{
if ( ddlMember.SelectedValue != null )
{
var ids = ddlMember.SelectedValue.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
if ( ids.Length == 2 )
{
var dbLocation = new LocationService( rockContext ).Get( int.Parse( ids[0] ) );
if ( dbLocation != null )
{
location = dbLocation;
}
memberPersonAliasId = new PersonAliasService( rockContext ).GetPrimaryAliasId( int.Parse( ids[1] ) );
}
}
}
else
{
if ( locpGroupLocation.Location != null )
{
location = new LocationService( rockContext ).Get( locpGroupLocation.Location.Id );
}
}
if ( location != null )
{
GroupLocation groupLocation = group.GroupLocations.FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
groupLocation.GroupMemberPersonAliasId = memberPersonAliasId;
groupLocation.Location = location;
groupLocation.LocationId = groupLocation.Location.Id;
groupLocation.GroupLocationTypeValueId = ddlLocationType.SelectedValueAsId();
}
}
rockContext.SaveChanges();
group.SaveAttributeValues( rockContext );
}
this.IsEditingGroup = false;
// reload the group info
pnlGroupEdit.Visible = false;
pnlGroupView.Visible = true;
DisplayViewGroup();
}
示例10: 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 )
{
if ( string.IsNullOrWhiteSpace( txtFirstName.Text ) ||
string.IsNullOrWhiteSpace( txtLastName.Text ) ||
string.IsNullOrWhiteSpace( txtEmail.Text ) )
{
ShowError( "Missing Information", "Please enter a value for First Name, Last Name, and Email" );
}
else
{
var rockContext = new RockContext();
var person = GetPerson( rockContext );
if ( person != null )
{
Guid? groupGuid = GetAttributeValue( "Group" ).AsGuidOrNull();
if ( groupGuid.HasValue )
{
var groupService = new GroupService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var group = groupService.Get( groupGuid.Value );
if ( group != null && group.GroupType.DefaultGroupRoleId.HasValue )
{
string linkedPage = GetAttributeValue( "ConfirmationPage" );
if ( !string.IsNullOrWhiteSpace( linkedPage ) )
{
var member = group.Members.Where( m => m.PersonId == person.Id ).FirstOrDefault();
// If person has not registered or confirmed their registration
if ( member == null || member.GroupMemberStatus != GroupMemberStatus.Active )
{
Guid confirmationEmailTemplateGuid = Guid.Empty;
if ( !Guid.TryParse( GetAttributeValue( "ConfirmationEmail" ), out confirmationEmailTemplateGuid ) )
{
confirmationEmailTemplateGuid = Guid.Empty;
}
if ( member == null )
{
member = new GroupMember();
member.GroupId = group.Id;
member.PersonId = person.Id;
member.GroupRoleId = group.GroupType.DefaultGroupRoleId.Value;
// If a confirmation email is configured, set status to Pending otherwise set it to active
member.GroupMemberStatus = confirmationEmailTemplateGuid != Guid.Empty ? GroupMemberStatus.Pending : GroupMemberStatus.Active;
groupMemberService.Add( member );
rockContext.SaveChanges();
member = groupMemberService.Get( member.Id );
}
// Send the confirmation
if ( confirmationEmailTemplateGuid != Guid.Empty )
{
var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson );
mergeFields.Add( "Member", member );
var pageParams = new Dictionary<string, string>();
pageParams.Add( "gm", member.UrlEncodedKey );
var pageReference = new Rock.Web.PageReference( linkedPage, pageParams );
mergeFields.Add( "ConfirmationPage", pageReference.BuildUrl() );
var recipients = new List<RecipientData>();
recipients.Add( new RecipientData( person.Email, mergeFields ) );
Email.Send( confirmationEmailTemplateGuid, recipients, ResolveRockUrl( "~/" ), ResolveRockUrl( "~~/" ) );
}
ShowSuccess( GetAttributeValue( "SuccessMessage" ) );
}
else
{
var pageParams = new Dictionary<string, string>();
pageParams.Add( "gm", member.UrlEncodedKey );
var pageReference = new Rock.Web.PageReference( linkedPage, pageParams );
Response.Redirect( pageReference.BuildUrl(), false );
}
}
else
{
ShowError( "Configuration Error", "Invalid Confirmation Page setting" );
}
}
else
{
ShowError( "Configuration Error", "The configured group does not exist, or it's group type does not have a default role configured." );
}
}
else
{
ShowError( "Configuration Error", "Invalid Group setting" );
}
}
//.........这里部分代码省略.........
示例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 )
{
bool hasValidationErrors = false;
var rockContext = new RockContext();
GroupTypeService groupTypeService = new GroupTypeService( rockContext );
GroupService groupService = new GroupService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
int parentGroupTypeId = hfParentGroupTypeId.ValueAsInt();
var groupTypeUIList = new List<GroupType>();
foreach ( var checkinGroupTypeEditor in phCheckinGroupTypes.Controls.OfType<CheckinGroupTypeEditor>().ToList() )
{
var groupType = checkinGroupTypeEditor.GetCheckinGroupType( rockContext );
groupTypeUIList.Add( groupType );
}
var groupTypeDBList = new List<GroupType>();
var groupTypesToDelete = new List<GroupType>();
var groupsToDelete = new List<Group>();
var groupTypesToAddUpdate = new List<GroupType>();
var groupsToAddUpdate = new List<Group>();
GroupType parentGroupTypeDB = groupTypeService.Get( parentGroupTypeId );
GroupType parentGroupTypeUI = parentGroupTypeDB.Clone( false );
parentGroupTypeUI.ChildGroupTypes = groupTypeUIList;
PopulateDeleteLists( groupTypesToDelete, groupsToDelete, parentGroupTypeDB, parentGroupTypeUI );
PopulateAddUpdateLists( groupTypesToAddUpdate, groupsToAddUpdate, parentGroupTypeUI );
int binaryFileFieldTypeID = FieldTypeCache.Read( Rock.SystemGuid.FieldType.BINARY_FILE.AsGuid() ).Id;
rockContext.WrapTransaction( () =>
{
// delete in reverse order to get deepest child items first
groupsToDelete.Reverse();
foreach ( var groupToDelete in groupsToDelete )
{
groupService.Delete( groupToDelete );
}
// delete in reverse order to get deepest child items first
groupTypesToDelete.Reverse();
foreach ( var groupTypeToDelete in groupTypesToDelete )
{
groupTypeService.Delete( groupTypeToDelete );
}
rockContext.SaveChanges();
// Add/Update grouptypes and groups that are in the UI
// Note: We'll have to save all the groupTypes without changing the DB value of ChildGroupTypes, then come around again and save the ChildGroupTypes
// since the ChildGroupTypes may not exist in the database yet
foreach ( GroupType groupTypeUI in groupTypesToAddUpdate )
{
GroupType groupTypeDB = groupTypeService.Get( groupTypeUI.Guid );
if ( groupTypeDB == null )
{
groupTypeDB = new GroupType();
groupTypeDB.Id = 0;
groupTypeDB.Guid = groupTypeUI.Guid;
groupTypeDB.IsSystem = false;
groupTypeDB.ShowInNavigation = false;
groupTypeDB.ShowInGroupList = false;
groupTypeDB.TakesAttendance = true;
groupTypeDB.AttendanceRule = AttendanceRule.None;
groupTypeDB.AttendancePrintTo = PrintTo.Default;
groupTypeDB.AllowMultipleLocations = true;
groupTypeDB.EnableLocationSchedules = true;
}
groupTypeDB.Name = groupTypeUI.Name;
groupTypeDB.Order = groupTypeUI.Order;
groupTypeDB.InheritedGroupTypeId = groupTypeUI.InheritedGroupTypeId;
groupTypeDB.Attributes = groupTypeUI.Attributes;
groupTypeDB.AttributeValues = groupTypeUI.AttributeValues;
if ( groupTypeDB.Id == 0 )
{
groupTypeService.Add( groupTypeDB );
}
if ( !groupTypeDB.IsValid )
{
hasValidationErrors = true;
CheckinGroupTypeEditor groupTypeEditor = phCheckinGroupTypes.ControlsOfTypeRecursive<CheckinGroupTypeEditor>().First( a => a.GroupTypeGuid == groupTypeDB.Guid );
groupTypeEditor.Expanded = true;
//.........这里部分代码省略.........
示例12: CheckSettings
/// <summary>
/// Checks the settings.
/// </summary>
/// <returns></returns>
private bool CheckSettings()
{
_rockContext = _rockContext ?? new RockContext();
_mode = GetAttributeValue( "Mode" );
_autoFill = GetAttributeValue( "AutoFillForm" ).AsBoolean();
tbEmail.Required = _autoFill;
string registerButtonText = GetAttributeValue( "RegisterButtonAltText" );
if ( string.IsNullOrWhiteSpace( registerButtonText ) )
{
registerButtonText = "Register";
}
btnRegister.Text = registerButtonText;
var groupService = new GroupService( _rockContext );
bool groupIsFromQryString = true;
Guid? groupGuid = GetAttributeValue( "Group" ).AsGuidOrNull();
if ( groupGuid.HasValue )
{
_group = groupService.Get( groupGuid.Value );
groupIsFromQryString = false;
}
if ( _group == null )
{
groupGuid = PageParameter( "GroupGuid" ).AsGuidOrNull();
if ( groupGuid.HasValue )
{
_group = groupService.Get( groupGuid.Value );
}
}
if ( _group == null )
{
int? groupId = PageParameter( "GroupId" ).AsIntegerOrNull();
if ( groupId.HasValue )
{
_group = groupService.Get( groupId.Value );
}
}
if ( _group == null )
{
nbNotice.Heading = "Unknown Group";
nbNotice.Text = "<p>This page requires a valid group id parameter, and there was not one provided.</p>";
return false;
}
else
{
if ( groupIsFromQryString && ( _group.IsSecurityRole || _group.GroupType.Guid == Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) )
{
nbNotice.Heading = "Invalid Group";
nbNotice.Text = "<p>The selected group is a security group and this block cannot be used to add people to a security group (unless configured for that specific group).</p>";
return false;
}
else
{
_defaultGroupRole = _group.GroupType.DefaultGroupRole;
}
}
_dvcConnectionStatus = DefinedValueCache.Read( GetAttributeValue( "ConnectionStatus" ).AsGuid() );
if ( _dvcConnectionStatus == null )
{
nbNotice.Heading = "Invalid Connection Status";
nbNotice.Text = "<p>The selected Connection Status setting does not exist.</p>";
return false;
}
_dvcRecordStatus = DefinedValueCache.Read( GetAttributeValue( "RecordStatus" ).AsGuid() );
if ( _dvcRecordStatus == null )
{
nbNotice.Heading = "Invalid Record Status";
nbNotice.Text = "<p>The selected Record Status setting does not exist.</p>";
return false;
}
_married = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid() );
_homeAddressType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid() );
_familyType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() );
_adultRole = _familyType.Roles.FirstOrDefault( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ) );
if ( _married == null || _homeAddressType == null || _familyType == null || _adultRole == null )
{
nbNotice.Heading = "Missing System Value";
nbNotice.Text = "<p>There is a missing or invalid system value. Check the settings for Marital Status of 'Married', Location Type of 'Home', Group Type of 'Family', and Family Group Role of 'Adult'.</p>";
return false;
}
return true;
}
示例13: AddRegistrantsToGroup
/// <summary>
/// Adds the registrants to group.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="registration">The registration.</param>
private void AddRegistrantsToGroup( RockContext rockContext, Registration registration )
{
// If the registration instance linkage specified a group to add registrant to, add them if they're not already
// part of that group
if ( registration.GroupId.HasValue )
{
var groupService = new GroupService( rockContext );
var personAliasService = new PersonAliasService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var group = groupService.Get( registration.GroupId.Value );
if ( group != null )
{
foreach ( var registrant in registration.Registrants.Where( r => r.PersonAliasId.HasValue ).ToList() )
{
var personAlias = personAliasService.Get( registrant.PersonAliasId.Value );
GroupMember groupMember = group.Members.Where( m => m.PersonId == personAlias.PersonId ).FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMemberService.Add( groupMember );
groupMember.GroupId = group.Id;
groupMember.PersonId = personAlias.PersonId;
if ( RegistrationTemplate.GroupTypeId.HasValue &&
RegistrationTemplate.GroupTypeId == group.GroupTypeId &&
RegistrationTemplate.GroupMemberRoleId.HasValue )
{
groupMember.GroupRoleId = RegistrationTemplate.GroupMemberRoleId.Value;
groupMember.GroupMemberStatus = RegistrationTemplate.GroupMemberStatus;
}
else
{
if ( group.GroupType.DefaultGroupRoleId.HasValue )
{
groupMember.GroupRoleId = group.GroupType.DefaultGroupRoleId.Value;
}
else
{
groupMember.GroupRoleId = group.GroupType.Roles.Select( r => r.Id ).FirstOrDefault();
}
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
}
}
rockContext.SaveChanges();
registrant.GroupMemberId = groupMember != null ? groupMember.Id : (int?)null;
rockContext.SaveChanges();
// Set any of the template's group member attributes
groupMember.LoadAttributes();
var registrantInfo = RegistrationState.Registrants.FirstOrDefault( r => r.Guid == registrant.Guid );
if ( registrantInfo != null )
{
foreach ( var field in RegistrationTemplate.Forms
.SelectMany( f => f.Fields
.Where( t =>
t.FieldSource == RegistrationFieldSource.GroupMemberAttribute &&
t.AttributeId.HasValue ) ) )
{
// Find the registrant's value
var fieldValue = registrantInfo.FieldValues
.Where( f => f.Key == field.Id )
.Select( f => f.Value.FieldValue )
.FirstOrDefault();
if ( fieldValue != null )
{
var attribute = AttributeCache.Read( field.AttributeId.Value );
if ( attribute != null )
{
string originalValue = groupMember.GetAttributeValue( attribute.Key );
string newValue = fieldValue.ToString();
groupMember.SetAttributeValue( attribute.Key, fieldValue.ToString() );
if ( ( originalValue ?? string.Empty ).Trim() != ( newValue ?? string.Empty ).Trim() )
{
string formattedOriginalValue = string.Empty;
if ( !string.IsNullOrWhiteSpace( originalValue ) )
{
formattedOriginalValue = attribute.FieldType.Field.FormatValue( null, originalValue, attribute.QualifierValues, false );
}
string formattedNewValue = string.Empty;
if ( !string.IsNullOrWhiteSpace( newValue ) )
{
formattedNewValue = attribute.FieldType.Field.FormatValue( null, newValue, attribute.QualifierValues, false );
}
Helper.SaveAttributeValue( groupMember, attribute, newValue, rockContext );
}
}
}
//.........这里部分代码省略.........
示例14: lbSave_Click
/// <summary>
/// Handles the Click event of the lbSave 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 lbSave_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
Rock.Data.RockTransactionScope.WrapTransaction( () =>
{
var personService = new PersonService( rockContext );
var changes = new List<string>();
var business = new Person();
if ( int.Parse( hfBusinessId.Value ) != 0 )
{
business = personService.Get( int.Parse( hfBusinessId.Value ) );
}
// int? orphanedPhotoId = null;
// if ( business.PhotoId != imgPhoto.BinaryFileId )
// {
// orphanedPhotoId = business.PhotoId;
// business.PhotoId = imgPhoto.BinaryFileId;
// if ( orphanedPhotoId.HasValue )
// {
// if ( business.PhotoId.HasValue )
// {
// changes.Add( "Modified the photo." );
// }
// else
// {
// changes.Add( "Deleted the photo." );
// }
// }
// else if ( business.PhotoId.HasValue )
// {
// changes.Add( "Added a photo." );
// }
// }
// Business Name
History.EvaluateChange( changes, "First Name", business.FirstName, tbBusinessName.Text );
business.FirstName = tbBusinessName.Text;
// Phone Number
var phoneNumberTypeIds = new List<int>();
var homePhoneTypeId = new DefinedValueService( rockContext ).GetByGuid( new Guid( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ) ).Id;
if ( !string.IsNullOrWhiteSpace( PhoneNumber.CleanNumber( pnbPhone.Number ) ) )
{
var phoneNumber = business.PhoneNumbers.FirstOrDefault( n => n.NumberTypeValueId == homePhoneTypeId );
string oldPhoneNumber = string.Empty;
if ( phoneNumber == null )
{
phoneNumber = new PhoneNumber { NumberTypeValueId = homePhoneTypeId };
business.PhoneNumbers.Add( phoneNumber );
}
else
{
oldPhoneNumber = phoneNumber.NumberFormattedWithCountryCode;
}
phoneNumber.CountryCode = PhoneNumber.CleanNumber( pnbPhone.CountryCode );
phoneNumber.Number = PhoneNumber.CleanNumber( pnbPhone.Number );
phoneNumber.IsMessagingEnabled = cbSms.Checked;
phoneNumber.IsUnlisted = cbUnlisted.Checked;
phoneNumberTypeIds.Add( homePhoneTypeId );
History.EvaluateChange(
changes,
string.Format( "{0} Phone", DefinedValueCache.GetName( homePhoneTypeId ) ),
oldPhoneNumber,
phoneNumber.NumberFormattedWithCountryCode );
}
// Remove any blank numbers
var phoneNumberService = new PhoneNumberService( rockContext );
foreach ( var phoneNumber in business.PhoneNumbers
.Where( n => n.NumberTypeValueId.HasValue && !phoneNumberTypeIds.Contains( n.NumberTypeValueId.Value ) )
.ToList() )
{
History.EvaluateChange(
changes,
string.Format( "{0} Phone", DefinedValueCache.GetName( phoneNumber.NumberTypeValueId ) ),
phoneNumber.NumberFormatted,
string.Empty );
business.PhoneNumbers.Remove( phoneNumber );
phoneNumberService.Delete( phoneNumber );
}
// Record Type - this is always "business". it will never change.
business.RecordTypeValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid() ).Id;
// Record Status
int? newRecordStatusId = ddlRecordStatus.SelectedValueAsInt();
History.EvaluateChange( changes, "Record Status", DefinedValueCache.GetName( business.RecordStatusValueId ), DefinedValueCache.GetName( newRecordStatusId ) );
business.RecordStatusValueId = newRecordStatusId;
//.........这里部分代码省略.........
示例15: BindFamilies
private void BindFamilies()
{
if ( Person != null && Person.Id > 0 )
{
Guid familyGroupGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
using ( _rockContext = new RockContext() )
{
var memberService = new GroupMemberService( _rockContext );
var families = memberService.Queryable( true )
.Where( m =>
m.PersonId == Person.Id &&
m.Group.GroupType.Guid == familyGroupGuid
)
.Select( m => m.Group )
.ToList();
if ( !families.Any() )
{
var familyGroupType = GroupTypeCache.GetFamilyGroupType();
if ( familyGroupType != null )
{
var groupMember = new GroupMember();
groupMember.PersonId = Person.Id;
groupMember.GroupRoleId = familyGroupType.DefaultGroupRoleId.Value;
var family = new Group();
family.Name = Person.LastName;
family.GroupTypeId = familyGroupType.Id;
family.Members.Add( groupMember );
var groupService = new GroupService( _rockContext );
groupService.Add( family );
_rockContext.SaveChanges();
families.Add( groupService.Get( family.Id ) );
}
}
rptrFamilies.DataSource = families;
rptrFamilies.DataBind();
}
}
}