本文整理汇总了C#中Rock.Model.GroupMemberService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# GroupMemberService.Add方法的具体用法?C# GroupMemberService.Add怎么用?C# GroupMemberService.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupMemberService
的用法示例。
在下文中一共展示了GroupMemberService.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddGroupMember
/// <summary>
/// Adds the group member.
/// </summary>
/// <param name="familyGroup">The family group.</param>
/// <param name="person">The person.</param>
/// <returns></returns>
protected GroupMember AddGroupMember( int familyGroupId, Person person )
{
var rockContext = new RockContext();
GroupMember groupMember = new GroupMember();
groupMember.IsSystem = false;
groupMember.GroupId = familyGroupId;
groupMember.PersonId = person.Id;
if ( person.Age >= 18 )
{
groupMember.GroupRoleId = new GroupTypeRoleService( rockContext ).Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
}
else
{
groupMember.GroupRoleId = new GroupTypeRoleService( rockContext ).Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) ).Id;
}
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
groupMemberService.Add( groupMember );
rockContext.SaveChanges();
return groupMember;
}
示例2: SaveGroupMember
private void SaveGroupMember()
{
if ( Page.IsValid )
{
var rockContext = new RockContext();
// Verify valid group
var groupService = new GroupService( rockContext );
var group = groupService.Get( hfGroupId.ValueAsInt() );
if ( group == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// Check to see if a person was selected
int? personId = ppGroupMemberPerson.PersonId;
int? personAliasId = ppGroupMemberPerson.PersonAliasId;
if ( !personId.HasValue || !personAliasId.HasValue )
{
nbErrorMessage.Title = "Please select a Person";
return;
}
// check to see if the user selected a role
var role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
var groupMemberService = new GroupMemberService( rockContext );
var groupMemberRequirementService = new GroupMemberRequirementService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = group.Id;
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
groupMember.PersonId = personId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.Note = tbNote.Text;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
if ( cbIsNotified.Visible )
{
groupMember.IsNotified = cbIsNotified.Checked;
}
if ( pnlRequirements.Visible )
{
foreach ( var checkboxItem in cblManualRequirements.Items.OfType<ListItem>() )
{
int groupRequirementId = checkboxItem.Value.AsInteger();
var groupMemberRequirement = groupMember.GroupMemberRequirements.FirstOrDefault( a => a.GroupRequirementId == groupRequirementId );
bool metRequirement = checkboxItem.Selected;
if ( metRequirement )
{
if ( groupMemberRequirement == null )
{
groupMemberRequirement = new GroupMemberRequirement();
groupMemberRequirement.GroupRequirementId = groupRequirementId;
groupMember.GroupMemberRequirements.Add( groupMemberRequirement );
}
// set the RequirementMetDateTime if it hasn't been set already
groupMemberRequirement.RequirementMetDateTime = groupMemberRequirement.RequirementMetDateTime ?? RockDateTime.Now;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
else
{
if ( groupMemberRequirement != null )
{
// doesn't meets the requirement
groupMemberRequirement.RequirementMetDateTime = null;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
}
}
}
if ( group.RequiredSignatureDocumentTemplate != null )
{
var person = new PersonService( rockContext ).Get( personId.Value );
var documentService = new SignatureDocumentService( rockContext );
var binaryFileService = new BinaryFileService( rockContext );
//.........这里部分代码省略.........
示例3: SaveRegistration
/// <summary>
/// Saves the registration.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="hasPayment">if set to <c>true</c> [has payment].</param>
/// <returns></returns>
private Registration SaveRegistration( RockContext rockContext, bool hasPayment )
{
var registrationService = new RegistrationService( rockContext );
var registrantService = new RegistrationRegistrantService( rockContext );
var personService = new PersonService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
// variables to keep track of the family that new people should be added to
int? singleFamilyId = null;
var multipleFamilyGroupIds = new Dictionary<Guid, int>();
var dvcConnectionStatus = DefinedValueCache.Read( GetAttributeValue( "ConnectionStatus" ).AsGuid() );
var dvcRecordStatus = DefinedValueCache.Read( GetAttributeValue( "RecordStatus" ).AsGuid() );
var familyGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
var adultRoleId = familyGroupType.Roles
.Where( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ) )
.Select( r => r.Id )
.FirstOrDefault();
var childRoleId = familyGroupType.Roles
.Where( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid() ) )
.Select( r => r.Id )
.FirstOrDefault();
var registration = new Registration();
registrationService.Add( registration );
registration.RegistrationInstanceId = RegistrationInstanceState.Id;
registration.GroupId = GroupId;
registration.FirstName = RegistrationState.FirstName;
registration.LastName = RegistrationState.LastName;
registration.ConfirmationEmail = RegistrationState.ConfirmationEmail;
registration.DiscountCode = RegistrationState.DiscountCode;
registration.DiscountAmount = RegistrationState.DiscountAmount;
registration.DiscountPercentage = RegistrationState.DiscountPercentage;
// If the 'your name' value equals the currently logged in person, use their person alias id
if ( CurrentPerson != null &&
( CurrentPerson.NickName.Trim().Equals( registration.FirstName.Trim(), StringComparison.OrdinalIgnoreCase ) ||
CurrentPerson.FirstName.Trim().Equals( registration.FirstName.Trim(), StringComparison.OrdinalIgnoreCase ) ) &&
CurrentPerson.LastName.Trim().Equals( registration.LastName.Trim(), StringComparison.OrdinalIgnoreCase ) )
{
registration.PersonAliasId = CurrentPerson.PrimaryAliasId;
}
else
{
// otherwise look for one and one-only match by name/email
var personMatches = personService.GetByMatch( registration.FirstName, registration.LastName, registration.ConfirmationEmail );
if ( personMatches.Count() == 1 )
{
registration.PersonAliasId = personMatches.First().PrimaryAliasId;
}
}
// If the registration includes a payment, make sure there's an actual person associated to registration
if ( hasPayment && !registration.PersonAliasId.HasValue )
{
// If a match was not found, create a new person
var person = new Person();
person.FirstName = registration.FirstName;
person.LastName = registration.LastName;
person.IsEmailActive = true;
person.Email = registration.ConfirmationEmail;
person.EmailPreference = EmailPreference.EmailAllowed;
person.RecordTypeValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id;
if ( dvcConnectionStatus != null )
{
person.ConnectionStatusValueId = dvcConnectionStatus.Id;
}
if ( dvcRecordStatus != null )
{
person.RecordStatusValueId = dvcRecordStatus.Id;
}
registration.PersonAliasId = SavePerson( rockContext, person, Guid.NewGuid(), null, null, adultRoleId, childRoleId, multipleFamilyGroupIds, singleFamilyId );
}
// Save the registration ( so we can get an id )
rockContext.SaveChanges();
// If the Registration Instance linkage specified a group, load it now
Group group = null;
if ( GroupId.HasValue )
{
group = new GroupService( rockContext ).Get( GroupId.Value );
}
// Get each registrant
foreach ( var registrantInfo in RegistrationState.Registrants )
{
var changes = new List<string>();
var familyChanges = new List<string>();
Person person = null;
// Try to find a matching person based on name and email address
//.........这里部分代码省略.........
示例4: LoadDropDowns
/// <summary>
/// Loads the drop downs.
/// </summary>
private void LoadDropDowns( BenevolenceRequest benevolenceRequest )
{
ddlRequestStatus.BindToDefinedType( DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.BENEVOLENCE_REQUEST_STATUS ) ), false );
ddlConnectionStatus.BindToDefinedType( DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS ) ), true );
Guid groupGuid = GetAttributeValue( "CaseWorkerRole" ).AsGuid();
var personList = new GroupMemberService( new RockContext() )
.Queryable( "Person, Group" )
.Where( gm => gm.Group.Guid == groupGuid )
.Select( gm => gm.Person )
.ToList();
string caseWorkerPersonAliasValue = benevolenceRequest.CaseWorkerPersonAliasId.ToString();
if ( benevolenceRequest.CaseWorkerPersonAlias != null &&
benevolenceRequest.CaseWorkerPersonAlias.Person != null &&
!personList.Select( p => p.Id ).ToList().Contains( benevolenceRequest.CaseWorkerPersonAlias.Person.Id ) )
{
personList.Add( benevolenceRequest.CaseWorkerPersonAlias.Person );
}
ddlCaseWorker.DataSource = personList.OrderBy( p => p.NickName ).ThenBy( p => p.LastName ).ToList();
ddlCaseWorker.DataTextField = "FullName";
ddlCaseWorker.DataValueField = "PrimaryAliasId";
ddlCaseWorker.DataBind();
ddlCaseWorker.Items.Insert( 0, new ListItem() );
}
示例5: 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 ( Page.IsValid )
{
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
GroupTypeRole role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
// check to see if the user selected a role
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = hfGroupId.ValueAsInt();
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
groupMember.PersonId = ppGroupMemberPerson.PersonId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
if ( !Page.IsValid )
{
return;
}
cvGroupMember.IsValid = groupMember.IsValid;
if ( !cvGroupMember.IsValid )
{
cvGroupMember.ErrorMessage = groupMember.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
// using WrapTransaction because there are two Saves
rockContext.WrapTransaction( () =>
{
if ( groupMember.Id.Equals( 0 ) )
{
groupMemberService.Add( groupMember );
}
rockContext.SaveChanges();
groupMember.SaveAttributeValues( rockContext );
} );
Group group = new GroupService( rockContext ).Get( groupMember.GroupId );
if ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) )
{
Rock.Security.Role.Flush( group.Id );
Rock.Security.Authorization.Flush();
}
}
Dictionary<string, string> qryString = new Dictionary<string, string>();
qryString["GroupId"] = hfGroupId.Value;
NavigateToParentPage( qryString );
}
示例6: AddPersonToGroup
/// <summary>
/// Adds the person to group.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="person">The person.</param>
/// <param name="workflowType">Type of the workflow.</param>
/// <param name="groupMembers">The group members.</param>
private void AddPersonToGroup( RockContext rockContext, Person person, WorkflowType workflowType, List<GroupMember> groupMembers )
{
if (person != null )
{
if ( !_group.Members
.Any( m =>
m.PersonId == person.Id &&
m.GroupRoleId == _defaultGroupRole.Id))
{
var groupMemberService = new GroupMemberService(rockContext);
var groupMember = new GroupMember();
groupMember.PersonId = person.Id;
groupMember.GroupRoleId = _defaultGroupRole.Id;
groupMember.GroupMemberStatus = (GroupMemberStatus)GetAttributeValue("GroupMemberStatus").AsInteger();
groupMember.GroupId = _group.Id;
groupMemberService.Add( groupMember );
rockContext.SaveChanges();
if ( workflowType != null )
{
try
{
List<string> workflowErrors;
var workflow = Workflow.Activate( workflowType, person.FullName );
new WorkflowService( rockContext ).Process( workflow, groupMember, out workflowErrors );
}
catch (Exception ex)
{
ExceptionLogService.LogException( ex, this.Context );
}
}
}
}
}
示例7: UpdateGroupMember
/// <summary>
/// Updates the group member.
/// </summary>
/// <param name="businessId">The business identifier.</param>
/// <param name="groupType">Type of the group.</param>
/// <param name="groupName">Name of the group.</param>
/// <param name="campusId">The campus identifier.</param>
/// <param name="groupRoleId">The group role identifier.</param>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
private GroupMember UpdateGroupMember( int businessId, GroupTypeCache groupType, string groupName, int? campusId, int groupRoleId, RockContext rockContext )
{
var groupMemberService = new GroupMemberService( rockContext );
GroupMember groupMember = groupMemberService.Queryable( "Group" )
.Where( m =>
m.PersonId == businessId &&
m.GroupRoleId == groupRoleId )
.FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMember.Group = new Group();
groupMemberService.Add( groupMember );
}
groupMember.PersonId = businessId;
groupMember.GroupRoleId = groupRoleId;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
groupMember.Group.GroupTypeId = groupType.Id;
groupMember.Group.Name = groupName;
groupMember.Group.CampusId = campusId;
return groupMember;
}
示例8: 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 ( Page.IsValid )
{
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
GroupMemberRequirementService groupMemberRequirementService = new GroupMemberRequirementService( rockContext );
GroupMember groupMember;
int groupMemberId = int.Parse( hfGroupMemberId.Value );
GroupTypeRole role = new GroupTypeRoleService( rockContext ).Get( ddlGroupRole.SelectedValueAsInt() ?? 0 );
// check to see if the user selected a role
if ( role == null )
{
nbErrorMessage.Title = "Please select a Role";
return;
}
// if adding a new group member
if ( groupMemberId.Equals( 0 ) )
{
groupMember = new GroupMember { Id = 0 };
groupMember.GroupId = hfGroupId.ValueAsInt();
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
groupMember.PersonId = ppGroupMemberPerson.PersonId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.Note = tbNote.Text;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
if ( cbIsNotified.Visible )
{
groupMember.IsNotified = cbIsNotified.Checked;
}
if ( pnlRequirements.Visible )
{
foreach ( var checkboxItem in cblManualRequirements.Items.OfType<ListItem>() )
{
int groupRequirementId = checkboxItem.Value.AsInteger();
var groupMemberRequirement = groupMember.GroupMemberRequirements.FirstOrDefault( a => a.GroupRequirementId == groupRequirementId );
bool metRequirement = checkboxItem.Selected;
if ( metRequirement )
{
if ( groupMemberRequirement == null )
{
groupMemberRequirement = new GroupMemberRequirement();
groupMemberRequirement.GroupRequirementId = groupRequirementId;
groupMember.GroupMemberRequirements.Add( groupMemberRequirement );
}
// set the RequirementMetDateTime if it hasn't been set already
groupMemberRequirement.RequirementMetDateTime = groupMemberRequirement.RequirementMetDateTime ?? RockDateTime.Now;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
else
{
if ( groupMemberRequirement != null )
{
// doesn't meets the requirement
groupMemberRequirement.RequirementMetDateTime = null;
groupMemberRequirement.LastRequirementCheckDateTime = RockDateTime.Now;
}
}
}
}
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
if ( !Page.IsValid )
{
return;
}
// if the groupMember IsValue is false, and the UI controls didn't report any errors, it is probably because the custom rules of GroupMember didn't pass.
// So, make sure a message is displayed in the validation summary
cvGroupMember.IsValid = groupMember.IsValid;
if ( !cvGroupMember.IsValid )
{
cvGroupMember.ErrorMessage = groupMember.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
//.........这里部分代码省略.........
示例9: 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 );
}
}
}
//.........这里部分代码省略.........
示例10: modalAddPerson_SaveClick
void modalAddPerson_SaveClick( object sender, EventArgs e )
{
if ( ppPerson.PersonId.HasValue )
{
int? roleId = grpRole.GroupRoleId;
if ( roleId.HasValue )
{
var rockContext = new RockContext();
var memberService = new GroupMemberService( rockContext );
var group = memberService.Queryable()
.Where( m =>
m.PersonId == Person.Id &&
m.GroupRole.Guid == ownerRoleGuid
)
.Select( m => m.Group )
.FirstOrDefault();
if ( group != null )
{
GroupMember groupMember = null;
int? groupMemberId = hfRoleId.Value.AsIntegerOrNull();
if ( groupMemberId.HasValue )
{
groupMember = memberService.Queryable()
.Where( m => m.Id == groupMemberId.Value )
.FirstOrDefault();
}
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMember.GroupId = group.Id;
memberService.Add( groupMember );
}
GroupMember formerInverseGroupMember = null;
if ( IsKnownRelationships )
{
formerInverseGroupMember = memberService.GetInverseRelationship( groupMember, false, CurrentPersonAlias );
}
groupMember.PersonId = ppPerson.PersonId.Value;
groupMember.GroupRoleId = roleId.Value;
rockContext.SaveChanges();
if ( IsKnownRelationships )
{
var inverseGroupMember = memberService.GetInverseRelationship(
groupMember, bool.Parse( GetAttributeValue( "CreateGroup" ) ), CurrentPersonAlias );
if ( inverseGroupMember != null )
{
rockContext.SaveChanges();
if ( formerInverseGroupMember != null && formerInverseGroupMember.Id != inverseGroupMember.Id )
{
memberService.Delete( formerInverseGroupMember );
rockContext.SaveChanges();
}
}
}
}
}
}
HideDialog();
BindData();
}
示例11: btnSave_Click
protected void btnSave_Click( object sender, EventArgs e )
{
RockContext rockContext = new RockContext();
var attendanceService = new AttendanceService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
foreach ( RepeaterItem item in rptScheduleDates.Items )
{
var placeholder = item.FindControl( "phGroups" ) as PlaceHolder;
if (placeholder != null )
{
// get groups
foreach( Control control in placeholder.Controls )
{
if (control is DropDownList )
{
var ddlGroup = (DropDownList)control;
var groupId = ddlGroup.SelectedValue.AsInteger();
var scheduleId = ddlGroup.Attributes["schedule-id"].AsInteger();
var scheduleDate = ddlGroup.Attributes["schedule-date"].AsDateTime();
var originalGroupId = ddlGroup.Attributes["original-group-id"].AsInteger();
// check if person is already registered for this schedule
var attending = _personalSchedules.Where( p =>
p.Date.Date == scheduleDate.Value.Date
&& p.Schedule.Id == scheduleId
&& p.Group.Id == groupId )
.Any();
if ( originalGroupId != 0 && groupId == 0 )
{
RemovePersonRsvp( CurrentPerson, originalGroupId, scheduleId, scheduleDate );
}
else if (!attending && groupId != 0 )
{
// remove existing record
if ( originalGroupId != 0 )
{
RemovePersonRsvp( CurrentPerson, originalGroupId, scheduleId, scheduleDate );
}
// mark them as coming
var attendanceRecord = new Attendance();
attendanceRecord.PersonAliasId = CurrentPersonAliasId;
attendanceRecord.GroupId = groupId;
attendanceRecord.ScheduleId = scheduleId;
attendanceRecord.StartDateTime = scheduleDate.Value.Date;
attendanceRecord.RSVP = RSVP.Yes;
attendanceRecord.LocationId = _location.Id;
attendanceService.Add( attendanceRecord );
rockContext.SaveChanges();
// add them to the group
var groupMember = groupMemberService.Queryable().Where( m => m.PersonId == CurrentPersonId && m.GroupId == groupId ).FirstOrDefault();
if (groupMember == null )
{
bool createAsInactive = GetAttributeValue( "GroupMembersInactive" ).AsBoolean();
groupMember = new GroupMember();
groupMemberService.Add( groupMember );
groupMember.PersonId = CurrentPersonId.Value;
groupMember.GroupId = groupId;
groupMember.GroupMemberStatus = createAsInactive ? GroupMemberStatus.Inactive : GroupMemberStatus.Active;
groupMember.GroupRoleId = _groupRoleId;
}
rockContext.SaveChanges();
var scheduleName = new ScheduleService( rockContext ).Queryable().Where( s => s.Id == scheduleId ).Select( s => s.Name ).FirstOrDefault();
if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "DescriptionAttribute" ) ) )
{
groupMember.LoadAttributes();
groupMember.SetAttributeValue( GetAttributeValue( "DescriptionAttribute" ), string.Format( "{0} {1}", scheduleDate.Value.ToShortDateString(), scheduleName ) );
groupMember.SaveAttributeValues();
}
}
}
}
}
}
nbMessages.NotificationBoxType = NotificationBoxType.Success;
nbMessages.Text = "Your changes have been saved.";
}
示例12: btnSave_Click
//.........这里部分代码省略.........
ddlGroupRole.SelectedItem.Text,
role.GroupType.GroupTerm,
RockPage.PageId,
existingGroupMember.Id );
return;
}
}
else
{
// load existing group member
groupMember = groupMemberService.Get( groupMemberId );
}
int memberCountInRole = new GroupMemberService( rockContext ).Queryable()
.Where( m =>
m.GroupId == groupMember.GroupId &&
m.GroupRoleId == role.Id &&
m.GroupMemberStatus == GroupMemberStatus.Active )
.Count();
bool roleMembershipAboveMax = false;
// if adding new active group member..
if ( groupMemberId.Equals( 0 ) && rblStatus.SelectedValueAsEnum<GroupMemberStatus>() == GroupMemberStatus.Active )
{
// verify that active count has not exceeded the max
if ( role.MaxCount != null && ( memberCountInRole + 1 ) > role.MaxCount )
{
roleMembershipAboveMax = true;
}
}
else if ( groupMemberId > 0 && ( groupMember.GroupRoleId != role.Id || groupMember.GroupMemberStatus != rblStatus.SelectedValueAsEnum<GroupMemberStatus>() )
&& rblStatus.SelectedValueAsEnum<GroupMemberStatus>() == GroupMemberStatus.Active )
{
// if existing group member changing role or status..
// verify that active count has not exceeded the max
if ( role.MaxCount != null && ( memberCountInRole + 1 ) > role.MaxCount )
{
roleMembershipAboveMax = true;
}
}
// show error if above max.. do not proceed
if ( roleMembershipAboveMax )
{
var person = new PersonService( rockContext ).Get( (int)ppGroupMemberPerson.PersonId );
nbErrorMessage.Title = string.Format( "Maximum {0} Exceeded", role.Name.Pluralize() );
nbErrorMessage.Text = string.Format(
"<br />The number of {0} for this {1} is at or above its maximum allowed limit of {2:N0} active {3}.",
role.Name.Pluralize(),
role.GroupType.GroupTerm,
role.MaxCount,
role.MaxCount == 1 ? role.GroupType.GroupMemberTerm : role.GroupType.GroupMemberTerm.Pluralize() );
return;
}
groupMember.PersonId = ppGroupMemberPerson.PersonId.Value;
groupMember.GroupRoleId = role.Id;
groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum<GroupMemberStatus>();
groupMember.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, groupMember );
if ( !Page.IsValid )
{
return;
}
if ( !groupMember.IsValid )
{
return;
}
// using WrapTransaction because there are two Saves
RockTransactionScope.WrapTransaction( () =>
{
if ( groupMember.Id.Equals( 0 ) )
{
groupMemberService.Add( groupMember );
}
groupMember.SaveAttributeValues( rockContext );
rockContext.SaveChanges();
} );
Group group = new GroupService( rockContext ).Get( groupMember.GroupId );
if ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) )
{
Rock.Security.Role.Flush( group.Id );
Rock.Security.Authorization.Flush();
}
}
Dictionary<string, string> qryString = new Dictionary<string, string>();
qryString["GroupId"] = hfGroupId.Value;
NavigateToParentPage( qryString );
}
示例13: AddRegistrantToGroup
private void AddRegistrantToGroup( int registrantId )
{
if ( RegistrationTemplateState != null &&
RegistrationTemplateState.GroupTypeId.HasValue &&
Registration.GroupId.HasValue )
{
using ( var rockContext = new RockContext() )
{
var registrant = new RegistrationRegistrantService( rockContext ).Get( registrantId );
if ( registrant != null && registrant.PersonId.HasValue && !registrant.GroupMemberId.HasValue )
{
var groupService = new GroupService( rockContext );
var group = groupService.Get( Registration.GroupId.Value );
if ( group != null && group.GroupTypeId == RegistrationTemplateState.GroupTypeId.Value )
{
int? groupRoleId = RegistrationTemplateState.GroupMemberRoleId.HasValue ?
RegistrationTemplateState.GroupMemberRoleId.Value :
group.GroupType.DefaultGroupRoleId;
if ( groupRoleId.HasValue )
{
var registrantChanges = new List<string>();
var groupMemberService = new GroupMemberService( rockContext );
var groupMember = groupMemberService
.Queryable().AsNoTracking()
.Where( m =>
m.GroupId == Registration.Group.Id &&
m.PersonId == registrant.PersonId &&
m.GroupRoleId == groupRoleId.Value )
.FirstOrDefault();
if ( groupMember == null )
{
groupMember = new GroupMember();
groupMemberService.Add( groupMember );
groupMember.GroupId = group.Id;
groupMember.PersonId = registrant.PersonId.Value;
groupMember.GroupRoleId = groupRoleId.Value;
groupMember.GroupMemberStatus = RegistrationTemplateState.GroupMemberStatus;
rockContext.SaveChanges();
registrantChanges.Add( string.Format( "Registrant added to {0} group", group.Name ) );
}
else
{
registrantChanges.Add( string.Format( "Registrant group member reference updated to existing person in {0} group", group.Name ) );
}
registrant.GroupMemberId = groupMember.Id;
rockContext.SaveChanges();
HistoryService.SaveChanges(
rockContext,
typeof( Registration ),
Rock.SystemGuid.Category.HISTORY_EVENT_REGISTRATION.AsGuid(),
registrant.RegistrationId,
registrantChanges,
"Registrant: " + CurrentPerson.FullName,
null, null );
}
}
}
}
}
}
示例14: btnMoveRegistration_Click
protected void btnMoveRegistration_Click( object sender, EventArgs e )
{
// set the new registration id
using ( var rockContext = new RockContext() )
{
var registrationService = new RegistrationService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var registration = registrationService.Get( Registration.Id );
registration.RegistrationInstanceId = ddlNewRegistrationInstance.SelectedValue.AsInteger();
// Move registrants to new group
int? groupId = ddlMoveGroup.SelectedValueAsInt();
if ( groupId.HasValue )
{
registration.GroupId = groupId;
rockContext.SaveChanges();
var group = new GroupService( rockContext ).Get( groupId.Value );
if ( group != null )
{
int? groupRoleId = null;
var template = registration.RegistrationInstance.RegistrationTemplate;
if ( group.GroupTypeId == template.GroupTypeId && template.GroupMemberRoleId.HasValue )
{
groupRoleId = template.GroupMemberRoleId.Value;
}
if ( !groupRoleId.HasValue )
{
groupRoleId = group.GroupType.DefaultGroupRoleId;
}
if ( !groupRoleId.HasValue )
{
groupRoleId = group.GroupType.Roles.OrderBy( r => r.Order ).Select( r => r.Id ).FirstOrDefault();
}
if ( groupRoleId.HasValue )
{
foreach ( var registrant in registration.Registrants.Where( r => r.PersonAlias != null ) )
{
var newGroupMembers = groupMemberService.GetByGroupIdAndPersonId( groupId.Value, registrant.PersonAlias.PersonId );
if ( !newGroupMembers.Any() )
{
// Get any existing group member attribute values
var existingAttributeValues = new Dictionary<string, string>();
if ( registrant.GroupMemberId.HasValue )
{
var existingGroupMember = groupMemberService.Get( registrant.GroupMemberId.Value );
if ( existingGroupMember != null )
{
existingGroupMember.LoadAttributes( rockContext );
foreach ( var attributeValue in existingGroupMember.AttributeValues )
{
existingAttributeValues.Add( attributeValue.Key, attributeValue.Value.Value );
}
}
registrant.GroupMember = null;
groupMemberService.Delete( existingGroupMember );
}
var newGroupMember = new GroupMember();
groupMemberService.Add( newGroupMember );
newGroupMember.Group = group;
newGroupMember.PersonId = registrant.PersonAlias.PersonId;
newGroupMember.GroupRoleId = groupRoleId.Value;
rockContext.SaveChanges();
newGroupMember = groupMemberService.Get( newGroupMember.Id );
newGroupMember.LoadAttributes();
foreach( var attr in newGroupMember.Attributes )
{
if ( existingAttributeValues.ContainsKey( attr.Key ) )
{
newGroupMember.SetAttributeValue( attr.Key, existingAttributeValues[attr.Key] );
}
}
newGroupMember.SaveAttributeValues( rockContext );
registrant.GroupMember = newGroupMember;
rockContext.SaveChanges();
}
}
}
}
}
// Reload registration
Registration = GetRegistration( Registration.Id );
lWizardInstanceName.Text = Registration.RegistrationInstance.Name;
ShowReadonlyDetails( Registration );
}
mdMoveRegistration.Hide();
}
示例15: 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" );
}
}
//.........这里部分代码省略.........