本文整理汇总了C#中Rock.Model.GroupService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.Add方法的具体用法?C# GroupService.Add怎么用?C# GroupService.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindFamilies
private void BindFamilies()
{
if ( Person != null && Person.Id > 0 )
{
Guid familyGroupGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
var memberService = new GroupMemberService();
var families = memberService.Queryable()
.Where( m =>
m.PersonId == Person.Id &&
m.Group.GroupType.Guid == familyGroupGuid
)
.Select( m => m.Group )
.ToList();
if ( !families.Any() )
{
var role = new GroupTypeRoleService().Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) );
if ( role != null && role.GroupTypeId.HasValue )
{
var groupMember = new GroupMember();
groupMember.PersonId = Person.Id;
groupMember.GroupRoleId = role.Id;
var family = new Group();
family.Name = Person.LastName;
family.GroupTypeId = role.GroupTypeId.Value;
family.Members.Add( groupMember );
var groupService = new GroupService();
groupService.Add( family, CurrentPersonId );
groupService.Save( family, CurrentPersonId );
families.Add( groupService.Get( family.Id ) );
}
}
rptrFamilies.DataSource = families;
rptrFamilies.DataBind();
}
}
示例2: BindData
/// <summary>
/// Binds the data.
/// </summary>
private void BindData()
{
if ( Person != null && Person.Id > 0 )
{
if ( ownerRoleGuid != Guid.Empty )
{
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 && bool.Parse( GetAttributeValue( "CreateGroup" ) ) )
{
var role = new GroupTypeRoleService( rockContext ).Get( ownerRoleGuid );
if ( role != null && role.GroupTypeId.HasValue )
{
var groupMember = new GroupMember();
groupMember.PersonId = Person.Id;
groupMember.GroupRoleId = role.Id;
group = new Group();
group.Name = role.GroupType.Name;
group.GroupTypeId = role.GroupTypeId.Value;
group.Members.Add( groupMember );
var groupService = new GroupService( rockContext );
groupService.Add( group );
rockContext.SaveChanges();
group = groupService.Get( group.Id );
}
}
if ( group != null )
{
if ( group.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
phGroupTypeIcon.Controls.Clear();
if ( !string.IsNullOrWhiteSpace( group.GroupType.IconCssClass ) )
{
phGroupTypeIcon.Controls.Add(
new LiteralControl(
string.Format( "<i class='{0}'></i>", group.GroupType.IconCssClass ) ) );
}
lGroupName.Text = group.Name;
phEditActions.Visible = group.IsAuthorized( Authorization.EDIT, CurrentPerson );
// TODO: How many implied relationships should be displayed
rGroupMembers.DataSource = new GroupMemberService( rockContext ).GetByGroupId( group.Id )
.Where( m => m.PersonId != Person.Id )
.OrderBy( m => m.Person.LastName )
.ThenBy( m => m.Person.FirstName )
.Take( 50 )
.ToList();
rGroupMembers.DataBind();
}
}
}
}
}
示例3: Execute
/// <summary>
/// Executes this instance.
/// </summary>
public void Execute()
{
using ( var rockContext = new RockContext() )
{
var relationshipGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid() );
if ( relationshipGroupType != null )
{
var ownerRole = relationshipGroupType.Roles
.Where( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid() ) )
.FirstOrDefault();
var friendRole = relationshipGroupType.Roles
.Where( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_FACEBOOK_FRIEND.AsGuid() ) )
.FirstOrDefault();
if ( ownerRole != null && friendRole != null )
{
var userLoginService = new UserLoginService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
// Convert list of facebook ids into list of usernames
var friendUserNames = FacebookIds.Select( i => "FACEBOOK_" + i ).ToList();
// Get the list of person ids associated with friends usernames
var friendPersonIds = userLoginService.Queryable()
.Where( l =>
l.PersonId.HasValue &&
l.PersonId != PersonId &&
friendUserNames.Contains( l.UserName ) )
.Select( l => l.PersonId.Value )
.Distinct()
.ToList();
// Get the person's group id
var personGroup = groupMemberService.Queryable()
.Where( m =>
m.PersonId == PersonId &&
m.GroupRoleId == ownerRole.Id &&
m.Group.GroupTypeId == relationshipGroupType.Id )
.Select( m => m.Group )
.FirstOrDefault();
// Verify that a 'known relationships' type group existed for the person, if not create it
if ( personGroup == null )
{
var groupMember = new GroupMember();
groupMember.PersonId = PersonId;
groupMember.GroupRoleId = ownerRole.Id;
personGroup = new Group();
personGroup.Name = relationshipGroupType.Name;
personGroup.GroupTypeId = relationshipGroupType.Id;
personGroup.Members.Add( groupMember );
var groupService = new GroupService( rockContext );
groupService.Add( personGroup );
rockContext.SaveChanges();
}
// Get the person's relationship group id
var personGroupId = personGroup.Id;
// Get all of the friend's relationship group ids
var friendGroupIds = groupMemberService.Queryable()
.Where( m =>
m.Group.GroupTypeId == relationshipGroupType.Id &&
m.GroupRoleId == ownerRole.Id &&
friendPersonIds.Contains( m.PersonId ) )
.Select( m => m.GroupId )
.Distinct()
.ToList();
// Find all the existing friend relationships in Rock ( both directions )
var existingFriends = groupMemberService.Queryable()
.Where( m =>
m.Group.GroupTypeId == relationshipGroupType.Id && (
( friendPersonIds.Contains( m.PersonId ) && m.GroupId == personGroupId ) ||
( m.PersonId == PersonId && m.GroupId != personGroupId )
) )
.ToList();
// Create temp group members for current Facebook friends
var currentFriends = new List<GroupMember>();
// ( Person > Friend )
foreach ( int personId in friendPersonIds )
{
var groupMember = new GroupMember();
groupMember.GroupId = personGroupId;
groupMember.PersonId = personId;
groupMember.GroupRoleId = friendRole.Id;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
currentFriends.Add( groupMember );
}
// ( Friend > Person )
foreach ( int familyId in friendGroupIds )
//.........这里部分代码省略.........
示例4: GetPersonOrBusiness
private Person GetPersonOrBusiness( Person person )
{
if ( person != null && phGiveAsOption.Visible && !tglGiveAsOption.Checked )
{
var rockContext = new RockContext();
var personService = new PersonService( rockContext );
var groupService = new GroupService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
Group familyGroup = null;
Person business = null;
int? businessId = cblBusiness.SelectedValueAsInt();
if ( businessId.HasValue )
{
business = personService.Get( businessId.Value );
}
if ( business == null )
{
DefinedValueCache dvcConnectionStatus = DefinedValueCache.Read( GetAttributeValue( "ConnectionStatus" ).AsGuid() );
DefinedValueCache dvcRecordStatus = DefinedValueCache.Read( GetAttributeValue( "RecordStatus" ).AsGuid() );
// Create Person
business = new Person();
business.LastName = txtLastName.Text;
business.IsEmailActive = true;
business.EmailPreference = EmailPreference.EmailAllowed;
business.RecordTypeValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid() ).Id;
if ( dvcConnectionStatus != null )
{
business.ConnectionStatusValueId = dvcConnectionStatus.Id;
}
if ( dvcRecordStatus != null )
{
business.RecordStatusValueId = dvcRecordStatus.Id;
}
// Create Person/Family
familyGroup = PersonService.SaveNewPerson( business, rockContext, null, false );
// Get the relationship roles to use
var knownRelationshipGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid() );
int businessContactRoleId = knownRelationshipGroupType.Roles
.Where( r =>
r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS_CONTACT.AsGuid() ) )
.Select( r => r.Id )
.FirstOrDefault();
int businessRoleId = knownRelationshipGroupType.Roles
.Where( r =>
r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS.AsGuid() ) )
.Select( r => r.Id )
.FirstOrDefault();
int ownerRoleId = knownRelationshipGroupType.Roles
.Where( r =>
r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid() ) )
.Select( r => r.Id )
.FirstOrDefault();
if ( ownerRoleId > 0 && businessContactRoleId > 0 && businessRoleId > 0 )
{
// get the known relationship group of the business contact
// add the business as a group member of that group using the group role of GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS
var contactKnownRelationshipGroup = groupMemberService.Queryable()
.Where( g =>
g.GroupRoleId == ownerRoleId &&
g.PersonId == person.Id )
.Select( g => g.Group )
.FirstOrDefault();
if ( contactKnownRelationshipGroup == null )
{
// In some cases person may not yet have a know relationship group type
contactKnownRelationshipGroup = new Group();
groupService.Add( contactKnownRelationshipGroup );
contactKnownRelationshipGroup.Name = "Known Relationship";
contactKnownRelationshipGroup.GroupTypeId = knownRelationshipGroupType.Id;
var ownerMember = new GroupMember();
ownerMember.PersonId = person.Id;
ownerMember.GroupRoleId = ownerRoleId;
contactKnownRelationshipGroup.Members.Add( ownerMember );
}
var groupMember = new GroupMember();
groupMember.PersonId = business.Id;
groupMember.GroupRoleId = businessRoleId;
contactKnownRelationshipGroup.Members.Add( groupMember );
// get the known relationship group of the business
// add the business contact as a group member of that group using the group role of GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS_CONTACT
var businessKnownRelationshipGroup = groupMemberService.Queryable()
.Where( g =>
g.GroupRole.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) ) &&
g.PersonId == business.Id )
.Select( g => g.Group )
.FirstOrDefault();
if ( businessKnownRelationshipGroup == null )
{
// In some cases business may not yet have a know relationship group type
businessKnownRelationshipGroup = new Group();
//.........这里部分代码省略.........
示例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 )
{
Group group;
bool wasSecurityRole = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
if ( ( ddlGroupType.SelectedValueAsInt() ?? 0 ) == 0 )
{
ddlGroupType.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( GroupType.FriendlyTypeName ) );
return;
}
int groupId = int.Parse( hfGroupId.Value );
if ( groupId == 0 )
{
group = new Group();
group.IsSystem = false;
group.Name = string.Empty;
}
else
{
group = groupService.Get( groupId );
wasSecurityRole = group.IsSecurityRole;
var selectedLocations = GroupLocationsState.Select( l => l.Guid );
foreach ( var groupLocation in group.GroupLocations.Where( l => !selectedLocations.Contains( l.Guid ) ).ToList() )
{
group.GroupLocations.Remove( groupLocation );
groupLocationService.Delete( groupLocation );
}
}
foreach ( var groupLocationState in GroupLocationsState )
{
GroupLocation groupLocation = group.GroupLocations.Where( l => l.Guid == groupLocationState.Guid ).FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
else
{
groupLocationState.Id = groupLocation.Id;
groupLocationState.Guid = groupLocation.Guid;
}
groupLocation.CopyPropertiesFrom( groupLocationState );
}
group.Name = tbName.Text;
group.Description = tbDescription.Text;
group.CampusId = ddlCampus.SelectedValue.Equals( None.IdValue ) ? (int?)null : int.Parse( ddlCampus.SelectedValue );
group.GroupTypeId = int.Parse( ddlGroupType.SelectedValue );
group.ParentGroupId = gpParentGroup.SelectedValue.Equals( None.IdValue ) ? (int?)null : int.Parse( gpParentGroup.SelectedValue );
group.IsSecurityRole = cbIsSecurityRole.Checked;
group.IsActive = cbIsActive.Checked;
if ( group.ParentGroupId == group.Id )
{
gpParentGroup.ShowErrorMessage( "Group cannot be a Parent Group of itself." );
return;
}
group.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phGroupAttributes, group );
if ( !Page.IsValid )
{
return;
}
if ( !group.IsValid )
{
// Controls will render the error messages
return;
}
// use WrapTransaction since SaveAttributeValues does it's own RockContext.SaveChanges()
RockTransactionScope.WrapTransaction( () =>
{
if ( group.Id.Equals( 0 ) )
{
groupService.Add( group );
}
rockContext.SaveChanges();
//.........这里部分代码省略.........
示例6: AddRelationships
/// <summary>
/// Adds a KnownRelationship record between the two supplied Guids with the given 'is' relationship type:
///
/// Role / inverse Role
/// ================================
/// step-parent / step-child
/// grandparent / grandchild
/// previous-spouse / previous-spouse
/// can-check-in / allow-check-in-by
/// parent / child
/// sibling / sibling
/// invited / invited-by
/// related / related
///
/// ...for xml such as:
/// <relationships>
/// <relationship a="Ben" personGuid="3C402382-3BD2-4337-A996-9E62F1BAB09D"
/// has="step-parent" forGuid="3D7F6605-3666-4AB5-9F4E-D7FEBF93278E" name="Brian" />
/// </relationships>
///
/// </summary>
/// <param name="elemRelationships"></param>
private void AddRelationships( XElement elemRelationships, RockContext rockContext )
{
if ( elemRelationships == null )
{
return;
}
Guid ownerRoleGuid = Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid();
Guid knownRelationshipsGroupTypeGuid = Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid();
var memberService = new GroupMemberService( rockContext );
var groupTypeRoles = new GroupTypeRoleService( rockContext ).Queryable( "GroupType" )
.Where( r => r.GroupType.Guid == knownRelationshipsGroupTypeGuid ).ToList();
//// We have to create (or fetch existing) two groups for each relationship, adding the
//// other person as a member of that group with the appropriate GroupTypeRole (GTR):
//// * a group with person as owner (GTR) and forPerson as type/role (GTR)
//// * a group with forPerson as owner (GTR) and person as inverse-type/role (GTR)
foreach ( var elemRelationship in elemRelationships.Elements( "relationship" ) )
{
// skip any illegally formatted items
if ( elemRelationship.Attribute( "personGuid" ) == null || elemRelationship.Attribute( "forGuid" ) == null ||
elemRelationship.Attribute( "has" ) == null )
{
continue;
}
Guid personGuid = elemRelationship.Attribute( "personGuid" ).Value.Trim().AsGuid();
Guid forGuid = elemRelationship.Attribute( "forGuid" ).Value.Trim().AsGuid();
int ownerPersonId = _peopleDictionary[personGuid];
int forPersonId = _peopleDictionary[forGuid];
string relationshipType = elemRelationship.Attribute( "has" ).Value.Trim();
int roleId = -1;
switch ( relationshipType )
{
case "step-parent":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_STEP_PARENT.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "step-child":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_STEP_CHILD.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "can-check-in":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "allow-check-in-by":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_ALLOW_CHECK_IN_BY.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "grandparent":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_GRANDPARENT.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "grandchild":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_GRANDCHILD.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
break;
case "invited":
roleId = groupTypeRoles.Where( r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED.AsGuid() )
.Select( r => r.Id ).FirstOrDefault();
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;
//.........这里部分代码省略.........
示例7: GetPerson
/// <summary>
/// Gets the person.
/// </summary>
/// <param name="create">if set to <c>true</c> [create].</param>
/// <returns></returns>
private Person GetPerson( bool create )
{
Person person = null;
int personId = ViewState["PersonId"] as int? ?? 0;
if ( personId == 0 && TargetPerson != null )
{
person = TargetPerson;
}
else
{
using ( new UnitOfWorkScope() )
{
var personService = new PersonService();
if ( personId != 0 )
{
person = personService.Get( personId );
}
if ( person == null && create )
{
// Check to see if there's only one person with same email, first name, and last name
if ( !string.IsNullOrWhiteSpace( txtEmail.Text ) &&
!string.IsNullOrWhiteSpace( txtFirstName.Text ) &&
!string.IsNullOrWhiteSpace( txtLastName.Text ) )
{
var personMatches = personService.GetByEmail( txtEmail.Text ).Where( p =>
p.LastName.Equals( txtLastName.Text, StringComparison.OrdinalIgnoreCase ) &&
( p.FirstName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ||
p.NickName.Equals( txtFirstName.Text, StringComparison.OrdinalIgnoreCase ) ) );
if ( personMatches.Count() == 1 )
{
person = personMatches.FirstOrDefault();
}
}
if ( person == null )
{
// Create Person
person = new Person();
person.FirstName = txtFirstName.Text;
person.LastName = txtLastName.Text;
person.Email = txtEmail.Text;
bool displayPhone = false;
if ( bool.TryParse( GetAttributeValue( "DisplayPhone" ), out displayPhone ) && displayPhone )
{
var phone = new PhoneNumber();
phone.Number = txtPhone.Text.AsNumeric();
phone.NumberTypeValueId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ) ).Id;
person.PhoneNumbers.Add( phone );
}
// Create Family Role
var groupMember = new GroupMember();
groupMember.Person = person;
groupMember.GroupRole = new GroupTypeRoleService().Get(new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) );
// Create Family
var group = new Group();
group.Members.Add( groupMember );
group.Name = person.LastName + " Family";
group.GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;
var groupLocation = new GroupLocation();
var location = new LocationService().Get(
txtStreet.Text, string.Empty, txtCity.Text, ddlState.SelectedValue, txtZip.Text );
if ( location != null )
{
Guid addressTypeGuid = Guid.Empty;
if ( !Guid.TryParse( GetAttributeValue( "AddressType" ), out addressTypeGuid ) )
{
addressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME );
}
groupLocation = new GroupLocation();
groupLocation.Location = location;
groupLocation.GroupLocationTypeValueId = DefinedValueCache.Read( addressTypeGuid ).Id;
group.GroupLocations.Add( groupLocation );
}
var groupService = new GroupService();
groupService.Add( group, CurrentPersonId );
groupService.Save( group, CurrentPersonId );
}
ViewState["PersonId"] = person != null ? person.Id : 0;
}
}
}
return person;
//.........这里部分代码省略.........
示例8: SaveNewPerson
/// <summary>
/// Adds a person alias, known relationship group, implied relationship group, and optionally a family group for
/// a new person.
/// </summary>
/// <param name="person">The person.</param>
/// <param name="rockContext">The rock context.</param>
/// <param name="campusId">The campus identifier.</param>
/// <param name="savePersonAttributes">if set to <c>true</c> [save person attributes].</param>
/// <returns>Family Group</returns>
public static Group SaveNewPerson ( Person person, RockContext rockContext, int? campusId = null, bool savePersonAttributes = false )
{
// Create/Save Known Relationship Group
var knownRelationshipGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS );
if ( knownRelationshipGroupType != null )
{
var ownerRole = knownRelationshipGroupType.Roles
.FirstOrDefault( r =>
r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid() ) );
if ( ownerRole != null )
{
var groupMember = new GroupMember();
groupMember.Person = person;
groupMember.GroupRoleId = ownerRole.Id;
var group = new Group();
group.Name = knownRelationshipGroupType.Name;
group.GroupTypeId = knownRelationshipGroupType.Id;
group.Members.Add( groupMember );
var groupService = new GroupService( rockContext );
groupService.Add( group );
}
}
// Create/Save Implied Relationship Group
var impliedRelationshipGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_IMPLIED_RELATIONSHIPS );
if ( impliedRelationshipGroupType != null )
{
var ownerRole = impliedRelationshipGroupType.Roles
.FirstOrDefault( r =>
r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_IMPLIED_RELATIONSHIPS_OWNER.AsGuid() ) );
if ( ownerRole != null )
{
var groupMember = new GroupMember();
groupMember.Person = person;
groupMember.GroupRoleId = ownerRole.Id;
var group = new Group();
group.Name = impliedRelationshipGroupType.Name;
group.GroupTypeId = impliedRelationshipGroupType.Id;
group.Members.Add( groupMember );
var groupService = new GroupService( rockContext );
groupService.Add( group );
}
}
// Create/Save family
var familyGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
if ( familyGroupType != null )
{
var adultRole = familyGroupType.Roles
.FirstOrDefault( r =>
r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ) );
if ( adultRole != null )
{
var groupMember = new GroupMember();
groupMember.Person = person;
groupMember.GroupRoleId = adultRole.Id;
var groupMembers = new List<GroupMember>();
groupMembers.Add( groupMember );
return GroupService.SaveNewFamily( rockContext, groupMembers, campusId, savePersonAttributes );
}
}
return null;
}
示例9: CheckinGroupRow_AddGroupClick
private void CheckinGroupRow_AddGroupClick( object sender, EventArgs e )
{
var parentRow = sender as CheckinGroupRow;
parentRow.Expanded = true;
using ( var rockContext = new RockContext() )
{
var groupService = new GroupService( rockContext );
var parentGroup = groupService.Get( parentRow.GroupGuid );
if ( parentGroup != null )
{
Guid newGuid = Guid.NewGuid();
var checkinGroup = new Group();
checkinGroup.Guid = newGuid;
checkinGroup.GroupTypeId = parentGroup.GroupTypeId;
checkinGroup.Name = "New Group";
checkinGroup.IsActive = true;
checkinGroup.IsPublic = true;
checkinGroup.IsSystem = false;
checkinGroup.Order = parentGroup.Groups.Any() ? parentGroup.Groups.Max( t => t.Order ) + 1 : 0;
checkinGroup.ParentGroupId = parentGroup.Id;
groupService.Add( checkinGroup );
rockContext.SaveChanges();
Rock.CheckIn.KioskDevice.FlushAll();
SelectGroup( newGuid );
}
}
BuildRows();
}
示例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 )
{
Group group;
bool wasSecurityRole = false;
bool triggersUpdated = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
GroupRequirementService groupRequirementService = new GroupRequirementService( rockContext );
GroupMemberWorkflowTriggerService groupMemberWorkflowTriggerService = new GroupMemberWorkflowTriggerService( rockContext );
ScheduleService scheduleService = new ScheduleService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
var roleGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
int roleGroupTypeId = roleGroupType != null ? roleGroupType.Id : int.MinValue;
if ( CurrentGroupTypeId == 0 )
{
ddlGroupType.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( GroupType.FriendlyTypeName ) );
return;
}
int groupId = hfGroupId.Value.AsInteger();
if ( groupId == 0 )
{
group = new Group();
group.IsSystem = false;
group.Name = string.Empty;
}
else
{
group = groupService.Queryable( "Schedule,GroupLocations.Schedules" ).Where( g => g.Id == groupId ).FirstOrDefault();
wasSecurityRole = group.IsActive && ( group.IsSecurityRole || group.GroupTypeId == roleGroupTypeId );
// remove any locations that removed in the UI
var selectedLocations = GroupLocationsState.Select( l => l.Guid );
foreach ( var groupLocation in group.GroupLocations.Where( l => !selectedLocations.Contains( l.Guid ) ).ToList() )
{
group.GroupLocations.Remove( groupLocation );
groupLocationService.Delete( groupLocation );
}
// remove any group requirements that removed in the UI
var selectedGroupRequirements = GroupRequirementsState.Select( a => a.Guid );
foreach ( var groupRequirement in group.GroupRequirements.Where( a => !selectedGroupRequirements.Contains( a.Guid ) ).ToList() )
{
group.GroupRequirements.Remove( groupRequirement );
groupRequirementService.Delete( groupRequirement );
}
// Remove any triggers that were removed in the UI
var selectedTriggerGuids = MemberWorkflowTriggersState.Select( r => r.Guid );
foreach ( var trigger in group.GroupMemberWorkflowTriggers.Where( r => !selectedTriggerGuids.Contains( r.Guid ) ).ToList() )
{
group.GroupMemberWorkflowTriggers.Remove( trigger );
groupMemberWorkflowTriggerService.Delete( trigger );
triggersUpdated = true;
}
}
// add/update any group requirements that were added or changed in the UI (we already removed the ones that were removed above)
foreach ( var groupRequirementState in GroupRequirementsState )
{
GroupRequirement groupRequirement = group.GroupRequirements.Where( a => a.Guid == groupRequirementState.Guid ).FirstOrDefault();
if ( groupRequirement == null )
{
groupRequirement = new GroupRequirement();
group.GroupRequirements.Add( groupRequirement );
}
groupRequirement.CopyPropertiesFrom( groupRequirementState );
}
// add/update any group locations that were added or changed in the UI (we already removed the ones that were removed above)
foreach ( var groupLocationState in GroupLocationsState )
{
GroupLocation groupLocation = group.GroupLocations.Where( l => l.Guid == groupLocationState.Guid ).FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
else
{
groupLocationState.Id = groupLocation.Id;
groupLocationState.Guid = groupLocation.Guid;
var selectedSchedules = groupLocationState.Schedules.Select( s => s.Guid ).ToList();
foreach ( var schedule in groupLocation.Schedules.Where( s => !selectedSchedules.Contains( s.Guid ) ).ToList() )
{
//.........这里部分代码省略.........
示例11: BindGroups
/// <summary>
/// Binds the groups.
/// </summary>
private void BindGroups()
{
if ( Person != null && Person.Id > 0 )
{
using ( _bindGroupsRockContext = new RockContext() )
{
var memberService = new GroupMemberService( _bindGroupsRockContext );
var groups = memberService.Queryable( true )
.Where( m =>
m.PersonId == Person.Id &&
m.Group.GroupTypeId == _groupType.Id )
.Select( m => m.Group )
.ToList();
if ( !groups.Any() && GetAttributeValue("AutoCreateGroup").AsBoolean(true) )
{
// ensure that the person is in a group
var groupService = new GroupService( _bindGroupsRockContext );
var group = new Group();
group.Name = Person.LastName;
group.GroupTypeId = _groupType.Id;
groupService.Add( group );
_bindGroupsRockContext.SaveChanges();
var groupMember = new GroupMember();
groupMember.PersonId = Person.Id;
groupMember.GroupRoleId = _groupType.DefaultGroupRoleId.Value;
groupMember.GroupId = group.Id;
group.Members.Add( groupMember );
_bindGroupsRockContext.SaveChanges();
groups.Add( groupService.Get( group.Id ) );
}
rptrGroups.DataSource = groups;
rptrGroups.DataBind();
}
}
}
示例12: CreateFamily
/// <summary>
/// Creates the family.
/// </summary>
/// <param name="FamilyName">Name of the family.</param>
/// <returns></returns>
protected Group CreateFamily( string FamilyName )
{
var familyGroup = new Group();
familyGroup.Name = FamilyName + " Family";
familyGroup.GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;
familyGroup.IsSecurityRole = false;
familyGroup.IsSystem = false;
familyGroup.IsActive = true;
Rock.Data.RockTransactionScope.WrapTransaction( () =>
{
var gs = new GroupService();
gs.Add( familyGroup, CurrentPersonId );
gs.Save( familyGroup, CurrentPersonId );
} );
return familyGroup;
}
示例13: btnNext_Click
protected void btnNext_Click( object sender, EventArgs e )
{
if ( Page.IsValid )
{
if ( CurrentCategoryIndex < attributeControls.Count )
{
CurrentCategoryIndex++;
ShowAttributeCategory( CurrentCategoryIndex );
}
else
{
var familyMembers = GetControlData();
if ( familyMembers.Any() )
{
RockTransactionScope.WrapTransaction( () =>
{
using ( new UnitOfWorkScope() )
{
var familyGroupType = GroupTypeCache.GetFamilyGroupType();
var familyChanges = new List<string>();
var familyMemberChanges = new Dictionary<Guid, List<string>>();
var familyDemographicChanges = new Dictionary<Guid, List<string>>();
if ( familyGroupType != null )
{
var groupService = new GroupService();
var groupTypeRoleService = new GroupTypeRoleService();
var familyGroup = new Group();
familyGroup.GroupTypeId = familyGroupType.Id;
familyChanges.Add("Created");
familyGroup.Name = familyMembers.FirstOrDefault().Person.LastName + " Family";
History.EvaluateChange( familyChanges, "Name", string.Empty, familyGroup.Name );
int? campusId = cpCampus.SelectedValueAsInt();
if (campusId.HasValue)
{
History.EvaluateChange( familyChanges, "Campus", string.Empty, CampusCache.Read( campusId.Value ).Name );
}
familyGroup.CampusId = campusId;
foreach(var familyMember in familyMembers)
{
var person = familyMember.Person;
if ( person != null )
{
familyGroup.Members.Add( familyMember );
var demographicChanges = new List<string>();
demographicChanges.Add( "Created" );
History.EvaluateChange( demographicChanges, "Record Status", string.Empty,
person.RecordStatusReasonValueId.HasValue ? DefinedValueCache.GetName( person.RecordStatusReasonValueId.Value ) : string.Empty );
History.EvaluateChange( demographicChanges, "Title", string.Empty,
person.TitleValueId.HasValue ? DefinedValueCache.GetName( person.TitleValueId ) : string.Empty );
History.EvaluateChange( demographicChanges, "First Name", string.Empty, person.FirstName);
History.EvaluateChange( demographicChanges, "Nick Name", string.Empty, person.NickName );
History.EvaluateChange( demographicChanges, "Middle Name", string.Empty, person.MiddleName );
History.EvaluateChange( demographicChanges, "Last Name", string.Empty, person.LastName );
History.EvaluateChange( demographicChanges, "Gender", null, person.Gender );
History.EvaluateChange( demographicChanges, "Birth Date", null, person.BirthDate );
History.EvaluateChange( demographicChanges, "Connection Status", string.Empty,
person.ConnectionStatusValueId.HasValue ? DefinedValueCache.GetName( person.ConnectionStatusValueId ) : string.Empty );
History.EvaluateChange( demographicChanges, "Graduation Date", null, person.GraduationDate );
familyDemographicChanges.Add( person.Guid, demographicChanges );
var memberChanges = new List<string>();
string roleName = familyGroupType.Roles[familyMember.GroupRoleId] ?? string.Empty;
History.EvaluateChange( memberChanges, "Role", string.Empty, roleName );
familyMemberChanges.Add( person.Guid, memberChanges );
}
}
if ( !String.IsNullOrWhiteSpace( tbStreet1.Text ) ||
!String.IsNullOrWhiteSpace( tbStreet2.Text ) ||
!String.IsNullOrWhiteSpace( tbCity.Text ) ||
!String.IsNullOrWhiteSpace( tbZip.Text ) )
{
string addressChangeField = "Address";
var groupLocation = new GroupLocation();
var location = new LocationService().Get(
tbStreet1.Text, tbStreet2.Text, tbCity.Text, ddlState.SelectedValue, tbZip.Text );
groupLocation.Location = location;
Guid locationTypeGuid = Guid.Empty;
if ( Guid.TryParse( GetAttributeValue( "LocationType" ), out locationTypeGuid ) )
{
var locationType = Rock.Web.Cache.DefinedValueCache.Read( locationTypeGuid );
if ( locationType != null )
{
addressChangeField = string.Format("{0} Address", locationType.Name);
groupLocation.GroupLocationTypeValueId = locationType.Id;
}
}
//.........这里部分代码省略.........
示例14: 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();
}
}
}
示例15: 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" ) )
{
//.........这里部分代码省略.........