本文整理汇总了C#中Rock.Model.GroupMemberService类的典型用法代码示例。如果您正苦于以下问题:C# GroupMemberService类的具体用法?C# GroupMemberService怎么用?C# GroupMemberService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GroupMemberService类属于Rock.Model命名空间,在下文中一共展示了GroupMemberService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes the specified context.
/// </summary>
/// <param name="context">The context.</param>
public void Execute( IJobExecutionContext context )
{
var rockContext = new RockContext();
var groupRequirementService = new GroupRequirementService( rockContext );
var groupMemberRequirementService = new GroupMemberRequirementService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
// we only need to consider group requirements that are based on a DataView or SQL
var groupRequirementQry = groupRequirementService.Queryable()
.Where( a => a.GroupRequirementType.RequirementCheckType != RequirementCheckType.Manual )
.AsNoTracking();
var calculationExceptions = new List<Exception>();
int groupRequirementsCalculatedMemberCount = 0;
foreach ( var groupRequirement in groupRequirementQry.Include( i => i.GroupRequirementType ).AsNoTracking().ToList() )
{
try
{
var currentDateTime = RockDateTime.Now;
var qryGroupMemberRequirementsAlreadyOK = groupMemberRequirementService.Queryable().Where( a => a.GroupRequirementId == groupRequirement.Id );
if ( groupRequirement.GroupRequirementType.CanExpire && groupRequirement.GroupRequirementType.ExpireInDays.HasValue )
{
// Expirable: don't recalculate members that already met the requirement within the expiredays (unless they are flagged with a warning)
var expireDaysCount = groupRequirement.GroupRequirementType.ExpireInDays.Value;
qryGroupMemberRequirementsAlreadyOK = qryGroupMemberRequirementsAlreadyOK.Where( a => !a.RequirementWarningDateTime.HasValue && a.RequirementMetDateTime.HasValue && SqlFunctions.DateDiff( "day", a.RequirementMetDateTime, currentDateTime ) < expireDaysCount );
}
else
{
// No Expiration: don't recalculate members that already met the requirement
qryGroupMemberRequirementsAlreadyOK = qryGroupMemberRequirementsAlreadyOK.Where( a => a.RequirementMetDateTime.HasValue );
}
var groupMemberQry = groupMemberService.Queryable().Where( a => a.GroupId == groupRequirement.GroupId ).AsNoTracking();
var personQry = groupMemberQry.Where( a => !qryGroupMemberRequirementsAlreadyOK.Any( r => r.GroupMemberId == a.Id ) ).Select( a => a.Person );
var results = groupRequirement.PersonQueryableMeetsGroupRequirement( rockContext, personQry, groupRequirement.GroupRoleId ).ToList();
groupRequirementsCalculatedMemberCount += results.Select( a => a.PersonId ).Distinct().Count();
foreach ( var result in results )
{
// use a fresh rockContext per Update so that ChangeTracker doesn't get bogged down
var rockContextUpdate = new RockContext();
groupRequirement.UpdateGroupMemberRequirementResult( rockContextUpdate, result.PersonId, result.MeetsGroupRequirement );
rockContextUpdate.SaveChanges();
}
}
catch ( Exception ex )
{
calculationExceptions.Add( new Exception( string.Format( "Exception when calculating group requirement: {0} ", groupRequirement ), ex ) );
}
}
context.Result = string.Format( "Group member requirements re-calculated for {0} group members", groupRequirementsCalculatedMemberCount );
if ( calculationExceptions.Any() )
{
throw new AggregateException( "One or more group requirement calculations failed ", calculationExceptions );
}
}
示例2: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
if ( checkInState != null )
{
var family = checkInState.CheckIn.Families.Where( f => f.Selected ).FirstOrDefault();
if ( family != null )
{
var service = new GroupMemberService( rockContext );
foreach ( var groupMember in service.GetByGroupId( family.Group.Id ).AsNoTracking().ToList() )
{
if ( !family.People.Any( p => p.Person.Id == groupMember.PersonId ) )
{
var person = new CheckInPerson();
person.Person = groupMember.Person.Clone( false );
person.FamilyMember = true;
family.People.Add( person );
}
}
return true;
}
else
{
errorMessages.Add( "There is not a family that is selected" );
}
return false;
}
return false;
}
示例3: OnInit
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
try
{
string groupMemberKey = PageParameter( "gm" );
if ( string.IsNullOrWhiteSpace( groupMemberKey ) )
{
ShowError( "Missing Parameter Value" );
}
else
{
var groupMemberService = new GroupMemberService();
var groupMember = groupMemberService.GetByUrlEncodedKey( PageParameter( "gm" ) );
if ( groupMember == null )
{
ShowError();
}
else
{
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
groupMemberService.Save( groupMember, CurrentPersonId );
nbMessage.NotificationBoxType = NotificationBoxType.Success;
nbMessage.Title = "Success";
nbMessage.Text = GetAttributeValue( "SuccessMessage" );
}
}
}
catch (SystemException ex)
{
ShowError( ex.Message );
}
}
示例4: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
if ( checkInState != null )
{
bool loadAll = false;
if ( bool.TryParse( GetAttributeValue( action, "LoadAll" ), out loadAll ) && loadAll )
{
loadAll = true;
}
foreach ( var family in checkInState.CheckIn.Families.Where( f => f.Selected ).ToList() )
{
foreach ( var person in family.People.Where( p => p.Selected || loadAll ).ToList() )
{
foreach ( var groupType in person.GroupTypes.Where( g => g.Selected || loadAll ).ToList() )
{
var kioskGroupType = checkInState.Kiosk.FilteredGroupTypes(checkInState.ConfiguredGroupTypes).Where( g => g.GroupType.Id == groupType.GroupType.Id ).FirstOrDefault();
if ( kioskGroupType != null )
{
foreach ( var kioskGroup in kioskGroupType.KioskGroups )
{
bool validGroup = true;
if ( groupType.GroupType.AttendanceRule == AttendanceRule.AlreadyBelongs )
{
validGroup = new GroupMemberService( rockContext ).Queryable()
.Any( m =>
m.GroupId == kioskGroup.Group.Id &&
m.PersonId == person.Person.Id );
}
if ( validGroup && !groupType.Groups.Any( g => g.Group.Id == kioskGroup.Group.Id ) )
{
var checkInGroup = new CheckInGroup();
checkInGroup.Group = kioskGroup.Group.Clone( false );
checkInGroup.Group.CopyAttributesFrom( kioskGroup.Group );
groupType.Groups.Add( checkInGroup );
}
}
}
}
}
}
return true;
}
return false;
}
示例5: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
if (checkInState != null)
{
using ( new Rock.Data.UnitOfWorkScope() )
{
var personService = new PersonService();
var memberService = new GroupMemberService();
IQueryable<Person> people = null;
if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER ) ) )
{
people = personService.GetByPhonePartial( checkInState.CheckIn.SearchValue );
}
else if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME ) ) )
{
people = personService.GetByFullName( checkInState.CheckIn.SearchValue );
}
else
{
errorMessages.Add( "Invalid Search Type" );
return false;
}
foreach ( var person in people.ToList() )
{
foreach ( var group in person.Members.Where( m => m.Group.GroupType.Guid == new Guid( SystemGuid.GroupType.GROUPTYPE_FAMILY ) ).Select( m => m.Group ).ToList() )
{
var family = checkInState.CheckIn.Families.Where( f => f.Group.Id == group.Id ).FirstOrDefault();
if ( family == null )
{
family = new CheckInFamily();
family.Group = group.Clone( false );
family.Group.LoadAttributes();
family.Caption = group.ToString();
family.SubCaption = memberService.GetFirstNames( group.Id ).ToList().AsDelimited( ", " );
checkInState.CheckIn.Families.Add( family );
}
}
}
return true;
}
}
errorMessages.Add( "Invalid Check-in State" );
return false;
}
示例6: Search
/// <summary>
/// Returns a list of matching people
/// </summary>
/// <param name="searchterm"></param>
/// <returns></returns>
public override IQueryable<string> Search( string searchterm )
{
Guid groupTypefamilyGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
Guid homeAddressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME );
var homeAddressTypeValueId = Rock.Web.Cache.DefinedValueCache.Read( homeAddressTypeGuid ).Id;
var service = new GroupMemberService( new RockContext() );
return service.Queryable()
.Where( m => m.Group.GroupType.Guid == groupTypefamilyGuid )
.SelectMany( g => g.Group.GroupLocations )
.Where( gl => gl.GroupLocationTypeValueId == homeAddressTypeValueId &&
gl.Location.Street1.Contains(searchterm) )
.Select( gl => gl.Location.Street1)
.Distinct();
}
示例7: GetInGroupOfType
public GroupOfTypeResult GetInGroupOfType(int personId, Guid groupTypeId)
{
GroupOfTypeResult result = new GroupOfTypeResult();
result.PersonId = personId;
result.PersonInGroup = false;
result.GroupList = new List<GroupSummary>();
// get person info
Person person = new PersonService( (Rock.Data.RockContext)Service.Context ).Get( personId );
if (person != null)
{
result.NickName = person.NickName;
result.LastName = person.LastName;
}
// get group type info
GroupType groupType = new GroupTypeService( (Rock.Data.RockContext)Service.Context ).Get( groupTypeId );
if (groupType != null)
{
result.GroupTypeName = groupType.Name;
result.GroupTypeIconCss = groupType.IconCssClass;
result.GroupTypeId = groupType.Id;
}
// determine if person is in this type of group
GroupMemberService groupMemberService = new GroupMemberService( (Rock.Data.RockContext)Service.Context );
IQueryable<GroupMember> groupMembershipsQuery = groupMemberService.Queryable("Person,GroupRole,Group")
.Where(t => t.Group.GroupType.Guid == groupTypeId && t.PersonId == personId )
.OrderBy(g => g.GroupRole.Order);
foreach (GroupMember member in groupMembershipsQuery)
{
result.PersonInGroup = true;
GroupSummary group = new GroupSummary();
group.GroupName = member.Group.Name;
group.GroupId = member.Group.Id;
group.RoleName = member.GroupRole.Name;
result.GroupList.Add(group);
}
return result;
}
示例8: CreateKnownRelationship
public System.Net.Http.HttpResponseMessage CreateKnownRelationship( int personId, int relatedPersonId, int relationshipRoleId )
{
SetProxyCreation( true );
var rockContext = this.Service.Context as RockContext;
var personService = new PersonService(rockContext);
var person = personService.Get(personId);
var relatedPerson = personService.Get(relatedPersonId);
CheckCanEdit( person );
CheckCanEdit( relatedPerson );
System.Web.HttpContext.Current.Items.Add( "CurrentPerson", GetPerson() );
var groupMemberService = new GroupMemberService(rockContext);
groupMemberService.CreateKnownRelationship( personId, relatedPersonId, relationshipRoleId );
return ControllerContext.Request.CreateResponse( HttpStatusCode.Created );
}
示例9: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
if ( checkInState != null )
{
var family = checkInState.CheckIn.CurrentFamily;
if ( family != null )
{
var service = new GroupMemberService( rockContext );
var people = service.GetByGroupId( family.Group.Id ).AsNoTracking();
if ( checkInState.CheckInType != null && checkInState.CheckInType.PreventInactivePeopele )
{
var dvInactive = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() );
if ( dvInactive != null )
{
people = people.Where( m => m.Person.RecordStatusValueId != dvInactive.Id );
}
}
foreach ( var groupMember in people.ToList() )
{
if ( !family.People.Any( p => p.Person.Id == groupMember.PersonId ) )
{
var person = new CheckInPerson();
person.Person = groupMember.Person.Clone( false );
person.FamilyMember = true;
family.People.Add( person );
}
}
return true;
}
else
{
errorMessages.Add( "There is not a family that is selected" );
}
return false;
}
return false;
}
示例10: PersonGroups
/// <summary>
/// The groups of a particular type that current person belongs to
/// </summary>
/// <returns></returns>
protected IEnumerable<Group> PersonGroups( int groupTypeId )
{
string itemKey = "RockGroups:" + groupTypeId.ToString();
var groups = Context.Items[itemKey] as IEnumerable<Group>;
if ( groups != null )
return groups;
if ( Person == null )
return null;
var service = new GroupMemberService();
groups = service.Queryable()
.Where( m =>
m.PersonId == Person.Id &&
m.Group.GroupTypeId == groupTypeId )
.Select( m => m.Group )
.OrderByDescending( g => g.Name );
Context.Items.Add( itemKey, groups );
return groups;
}
示例11: 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;
}
示例12: Execute
/// <summary>
/// Executes the specified context.
/// </summary>
/// <param name="context">The context.</param>
public virtual void Execute( IJobExecutionContext context )
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
var emailTemplateGuid = dataMap.Get( "SystemEmail" ).ToString().AsGuid();
var groupGuid = dataMap.Get( "Group" ).ToString().AsGuid();
var sendToDescendants = dataMap.Get( "SendToDescendantGroups" ).ToString().AsBoolean();
var rockContext = new RockContext();
var group = new GroupService( rockContext ).Get( groupGuid );
if ( group != null )
{
List<int> groupIds = new List<int>();
GetGroupIds( groupIds, sendToDescendants, group );
var recipients = new List<RecipientData>();
var groupMemberList = new GroupMemberService( rockContext ).Queryable().Where( gm =>
groupIds.Contains( gm.GroupId ) &&
gm.GroupMemberStatus == GroupMemberStatus.Active )
.ToList();
foreach ( GroupMember groupMember in groupMemberList )
{
var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( null );
mergeFields.Add( "Person", groupMember.Person );
mergeFields.Add( "GroupMember", groupMember );
mergeFields.Add( "Group", groupMember.Group );
recipients.Add( new RecipientData( groupMember.Person.Email, mergeFields ) );
}
var appRoot = Rock.Web.Cache.GlobalAttributesCache.Read( rockContext ).GetValue( "ExternalApplicationRoot" );
Email.Send( emailTemplateGuid, recipients, appRoot );
context.Result = string.Format( "{0} emails sent", recipients.Count() );
}
}
示例13: GetBreadCrumbs
/// <summary>
/// Returns breadcrumbs specific to the block that should be added to navigation
/// based on the current page reference. This function is called during the page's
/// oninit to load any initial breadcrumbs
/// </summary>
/// <param name="pageReference">The page reference.</param>
/// <returns></returns>
public override List<BreadCrumb> GetBreadCrumbs( PageReference pageReference )
{
var breadCrumbs = new List<BreadCrumb>();
int? groupMemberId = PageParameter( pageReference, "GroupMemberId" ).AsIntegerOrNull();
if ( groupMemberId != null )
{
GroupMember groupMember = new GroupMemberService( new RockContext() ).Get( groupMemberId.Value );
if ( groupMember != null )
{
var parentPageReference = PageReference.GetParentPageReferences( this.RockPage, this.PageCache, pageReference ).LastOrDefault();
if ( parentPageReference != null )
{
var groupIdParam = parentPageReference.QueryString["GroupId"].AsIntegerOrNull();
if ( !groupIdParam.HasValue || groupIdParam.Value != groupMember.GroupId)
{
// if the GroupMember's Group isn't included in the breadcrumbs, make sure to add the Group to the breadcrumbs so we know which group the group member is in
breadCrumbs.Add( new BreadCrumb( groupMember.Group.Name, true ) );
}
}
breadCrumbs.Add( new BreadCrumb( groupMember.Person.FullName, pageReference ) );
}
else
{
breadCrumbs.Add( new BreadCrumb( "New Group Member", pageReference ) );
}
}
else
{
// don't show a breadcrumb if we don't have a pageparam to work with
}
return breadCrumbs;
}
示例14: GetBreadCrumbs
/// <summary>
/// Returns breadcrumbs specific to the block that should be added to navigation
/// based on the current page reference. This function is called during the page's
/// oninit to load any initial breadcrumbs
/// </summary>
/// <param name="pageReference">The page reference.</param>
/// <returns></returns>
public override List<BreadCrumb> GetBreadCrumbs( PageReference pageReference )
{
var breadCrumbs = new List<BreadCrumb>();
int? groupMemberId = PageParameter( pageReference, "GroupMemberId" ).AsIntegerOrNull();
if ( groupMemberId != null )
{
GroupMember groupMember = new GroupMemberService( new RockContext() ).Get( groupMemberId.Value );
if ( groupMember != null )
{
breadCrumbs.Add( new BreadCrumb( groupMember.Person.FullName, pageReference ) );
}
else
{
breadCrumbs.Add( new BreadCrumb( "New Group Member", pageReference ) );
}
}
else
{
// don't show a breadcrumb if we don't have a pageparam to work with
}
return breadCrumbs;
}
示例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 )
{
// confirmation was disabled by btnSave on client-side. So if returning without a redirect,
// it should be enabled. If returning with a redirect, the control won't be updated to reflect
// confirmation being enabled, so it's ok to enable it here
confirmExit.Enabled = true;
if ( Page.IsValid )
{
confirmExit.Enabled = true;
RockTransactionScope.WrapTransaction( () =>
{
var rockContext = new RockContext();
var familyService = new GroupService( rockContext );
var familyMemberService = new GroupMemberService( rockContext );
var personService = new PersonService( rockContext );
var historyService = new HistoryService( rockContext );
var familyChanges = new List<string>();
// SAVE FAMILY
_family = familyService.Get( _family.Id );
History.EvaluateChange( familyChanges, "Family Name", _family.Name, tbFamilyName.Text );
_family.Name = tbFamilyName.Text;
int? campusId = cpCampus.SelectedValueAsInt();
if ( _family.CampusId != campusId )
{
History.EvaluateChange( familyChanges, "Campus",
_family.CampusId.HasValue ? CampusCache.Read( _family.CampusId.Value ).Name : string.Empty,
campusId.HasValue ? CampusCache.Read( campusId.Value ).Name : string.Empty );
_family.CampusId = campusId;
}
var familyGroupTypeId = _family.GroupTypeId;
rockContext.SaveChanges();
// SAVE FAMILY MEMBERS
int? recordStatusValueID = ddlRecordStatus.SelectedValueAsInt();
int? reasonValueId = ddlReason.SelectedValueAsInt();
var newFamilies = new List<Group>();
foreach ( var familyMember in FamilyMembers )
{
var memberChanges = new List<string>();
var demographicChanges = new List<string>();
var role = familyRoles.Where( r => r.Guid.Equals( familyMember.RoleGuid ) ).FirstOrDefault();
if ( role == null )
{
role = familyRoles.FirstOrDefault();
}
bool isChild = role != null && role.Guid.Equals( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) );
// People added to family (new or from other family)
if ( !familyMember.ExistingFamilyMember )
{
var groupMember = new GroupMember();
if ( familyMember.Id == -1 )
{
// added new person
demographicChanges.Add( "Created" );
var person = new Person();
person.FirstName = familyMember.FirstName;
person.NickName = familyMember.NickName;
History.EvaluateChange( demographicChanges, "First Name", string.Empty, person.FirstName );
person.LastName = familyMember.LastName;
History.EvaluateChange( demographicChanges, "Last Name", string.Empty, person.LastName );
person.Gender = familyMember.Gender;
History.EvaluateChange( demographicChanges, "Gender", null, person.Gender );
person.BirthDate = familyMember.BirthDate;
History.EvaluateChange( demographicChanges, "Birth Date", null, person.BirthDate );
if ( !isChild )
{
person.GivingGroupId = _family.Id;
History.EvaluateChange( demographicChanges, "Giving Group", string.Empty, _family.Name );
}
person.EmailPreference = EmailPreference.EmailAllowed;
groupMember.Person = person;
}
else
{
// added from other family
//.........这里部分代码省略.........