本文整理汇总了C#中Rock.Model.PersonService类的典型用法代码示例。如果您正苦于以下问题:C# PersonService类的具体用法?C# PersonService怎么用?C# PersonService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersonService类属于Rock.Model命名空间,在下文中一共展示了PersonService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetByAliasGuid
/// <summary>
/// Gets the by alias unique identifier.
/// </summary>
/// <param name="aliasPersonGuid">The alias person unique identifier.</param>
/// <returns></returns>
public virtual PersonAlias GetByAliasGuid( Guid aliasPersonGuid )
{
var personAlias = Queryable( "Person" ).Where( a => a.AliasPersonGuid == aliasPersonGuid ).FirstOrDefault();
if ( personAlias != null )
{
return personAlias;
}
else
{
// If the personId is valid, there should be a personAlias with the AliasPersonID equal
// to that personId. If there isn't for some reason, create it now.
var person = new PersonService( (RockContext)this.Context ).Get( aliasPersonGuid );
if ( person != null )
{
personAlias = new PersonAlias();
personAlias.Guid = Guid.NewGuid();
personAlias.AliasPersonId = person.Id;
personAlias.AliasPersonGuid = person.Guid;
personAlias.PersonId = person.Id;
// Use a different context so calling method's changes are not yet saved
var rockContext = new RockContext();
new PersonAliasService( rockContext ).Add( personAlias );
rockContext.SaveChanges();
return Get( personAlias.Id );
}
}
return null;
}
示例2: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="itemKey">The item key.</param>
/// <param name="itemKeyValue">The item key value.</param>
public void ShowDetail( string itemKey, int itemKeyValue )
{
var rockContext = new RockContext();
pnlDetails.Visible = false;
if ( !itemKey.Equals( "businessId" ) )
{
return;
}
bool editAllowed = true;
Person business = null; // A business is a person
if ( !itemKeyValue.Equals( 0 ) )
{
business = new PersonService( rockContext ).Get( itemKeyValue );
editAllowed = business.IsAuthorized( Authorization.EDIT, CurrentPerson );
}
else
{
business = new Person { Id = 0 };
}
if ( business == null )
{
return;
}
pnlDetails.Visible = true;
hfBusinessId.Value = business.Id.ToString();
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !editAllowed || !IsUserAuthorized( Authorization.EDIT ) )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Person.FriendlyTypeName );
}
if ( readOnly )
{
ShowSummary( business );
}
else
{
if ( business.Id > 0 )
{
ShowSummary( business );
}
else
{
ShowEditDetails( business );
}
}
BindContactListGrid( business );
}
示例3: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="businessId">The business identifier.</param>
public void ShowDetail( int businessId )
{
var rockContext = new RockContext();
// Load the Campus drop down
ddlCampus.Items.Clear();
ddlCampus.Items.Add( new ListItem( string.Empty, string.Empty ) );
foreach ( var campus in CampusCache.All() )
{
ListItem li = new ListItem( campus.Name, campus.Id.ToString() );
ddlCampus.Items.Add( li );
}
Person business = null; // A business is a person
if ( !businessId.Equals( 0 ) )
{
business = new PersonService( rockContext ).Get( businessId );
pdAuditDetails.SetEntity( business, ResolveRockUrl( "~" ) );
}
if ( business == null )
{
business = new Person { Id = 0, Guid = Guid.NewGuid() };
// hide the panel drawer that show created and last modified dates
pdAuditDetails.Visible = false;
}
bool editAllowed = business.IsAuthorized( Authorization.EDIT, CurrentPerson );
hfBusinessId.Value = business.Id.ToString();
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !editAllowed || !IsUserAuthorized( Authorization.EDIT ) )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Person.FriendlyTypeName );
}
if ( readOnly )
{
ShowSummary( businessId );
}
else
{
if ( business.Id > 0 )
{
ShowSummary( business.Id );
}
else
{
ShowEditDetails( business );
}
}
BindContactListGrid( business );
}
示例4: GetPersonFromId
protected Person GetPersonFromId(string PersonId)
{
int intPersonId = Int32.Parse(PersonId);
PersonService personService = new PersonService(rockContext);
var person = personService.Queryable().FirstOrDefault(p => p.Id == intPersonId);
return person;
}
示例5: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="businessId">The business identifier.</param>
public void ShowDetail( int businessId )
{
var rockContext = new RockContext();
// Load the Campus drop down
ddlCampus.Items.Clear();
ddlCampus.Items.Add( new ListItem( string.Empty, string.Empty ) );
var campusService = new CampusService( new RockContext() );
foreach ( Campus campus in campusService.Queryable() )
{
ListItem li = new ListItem( campus.Name, campus.Id.ToString() );
ddlCampus.Items.Add( li );
}
Person business = null; // A business is a person
if ( !businessId.Equals( 0 ) )
{
business = new PersonService( rockContext ).Get( businessId );
}
if ( business == null )
{
business = new Person { Id = 0, Guid = Guid.NewGuid() };
}
bool editAllowed = business.IsAuthorized( Authorization.EDIT, CurrentPerson );
hfBusinessId.Value = business.Id.ToString();
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !editAllowed || !IsUserAuthorized( Authorization.EDIT ) )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Person.FriendlyTypeName );
}
if ( readOnly )
{
ShowSummary( businessId );
}
else
{
if ( business.Id > 0 )
{
ShowSummary( business.Id );
}
else
{
ShowEditDetails( business );
}
}
BindContactListGrid( business );
}
示例6: Search
/// <summary>
/// Returns a list of matching people
/// </summary>
/// <param name="searchterm"></param>
/// <returns></returns>
public override IQueryable<string> Search( string searchterm )
{
var personService = new PersonService( new RockContext() );
return personService.Queryable().
Where( p => p.Email.Contains( searchterm ) ).
OrderBy( p => p.Email ).
Select( p => p.Email ).Distinct();
}
示例7: btnSubmit_Click
/// <summary>
/// Handles the Click event of the btnSubmit 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 btnSubmit_Click( object sender, EventArgs e )
{
if (_person != null)
{
var rockContext = new RockContext();
var service = new PersonService( rockContext );
var person = service.Get(_person.Id);
if ( person != null )
{
switch ( rblEmailPreference.SelectedValue )
{
case "0":
{
person.EmailPreference = EmailPreference.EmailAllowed;
break;
}
case "1":
{
person.EmailPreference = EmailPreference.NoMassEmails;
break;
}
case "2":
case "3":
{
person.EmailPreference = EmailPreference.DoNotEmail;
break;
}
}
if (rblEmailPreference.SelectedValue == "3")
{
person.RecordStatusValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ).Id;
person.RecordStatusReasonValueId = ddlInactiveReason.SelectedValue.AsInteger().Value;
person.ReviewReasonValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_REVIEW_REASON_SELF_INACTIVATED ).Id;
if ( string.IsNullOrWhiteSpace( person.ReviewReasonNote ) )
{
person.ReviewReasonNote = tbInactiveNote.Text;
}
else
{
person.ReviewReasonNote += " " + tbInactiveNote.Text;
}
}
else
{
person.RecordStatusValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ).Id;
person.RecordStatusReasonValueId = null;
}
rockContext.SaveChanges();
nbMessage.Visible = true;
return;
}
}
}
示例8: CreateEmailCommunication
/// <summary>
/// Creates the email communication.
/// </summary>
/// <param name="recipientEmails">The recipient emails.</param>
/// <param name="fromName">From name.</param>
/// <param name="fromAddress">From address.</param>
/// <param name="replyTo">The reply to.</param>
/// <param name="subject">The subject.</param>
/// <param name="htmlMessage">The HTML message.</param>
/// <param name="textMessage">The text message.</param>
/// <param name="bulkCommunication">if set to <c>true</c> [bulk communication].</param>
/// <param name="recipientStatus">The recipient status.</param>
/// <param name="senderPersonAliasId">The sender person alias identifier.</param>
/// <returns></returns>
public Communication CreateEmailCommunication(
List<string> recipientEmails,
string fromName,
string fromAddress,
string replyTo,
string subject,
string htmlMessage,
string textMessage,
bool bulkCommunication,
CommunicationRecipientStatus recipientStatus = CommunicationRecipientStatus.Delivered,
int? senderPersonAliasId = null )
{
var recipients = new PersonService( (RockContext)this.Context )
.Queryable()
.Where( p => recipientEmails.Contains( p.Email ) )
.ToList();
if ( recipients.Any() )
{
Rock.Model.Communication communication = new Rock.Model.Communication();
communication.Status = CommunicationStatus.Approved;
communication.SenderPersonAliasId = senderPersonAliasId;
communication.Subject = subject;
Add( communication );
communication.IsBulkCommunication = bulkCommunication;
communication.MediumEntityTypeId = EntityTypeCache.Read( "Rock.Communication.Medium.Email" ).Id;
communication.FutureSendDateTime = null;
// add each person as a recipient to the communication
foreach ( var person in recipients )
{
int? personAliasId = person.PrimaryAliasId;
if ( personAliasId.HasValue )
{
var communicationRecipient = new CommunicationRecipient();
communicationRecipient.PersonAliasId = personAliasId.Value;
communicationRecipient.Status = recipientStatus;
communication.Recipients.Add( communicationRecipient );
}
}
// add the MediumData to the communication
communication.MediumData.Clear();
communication.MediumData.Add( "FromName", fromName );
communication.MediumData.Add( "FromAddress", fromAddress );
communication.MediumData.Add( "ReplyTo", replyTo );
communication.MediumData.Add( "Subject", subject );
communication.MediumData.Add( "HtmlMessage", htmlMessage );
communication.MediumData.Add( "TextMessage", textMessage );
return communication;
}
return null;
}
示例9: gfPledges_DisplayFilterValue
/// <summary>
/// Gfs the pledges_ display filter value.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
/// <exception cref="System.NotImplementedException"></exception>
protected void gfPledges_DisplayFilterValue( object sender, GridFilter.DisplayFilterValueArgs e )
{
switch ( e.Key )
{
case "Date Range":
e.Value = DateRangePicker.FormatDelimitedValues( e.Value );
break;
case "Person":
int? personId = e.Value.AsIntegerOrNull();
if ( personId != null )
{
var person = new PersonService( new RockContext() ).Get( personId.Value );
if ( person != null )
{
e.Value = person.ToString();
}
else
{
e.Value = string.Empty;
}
}
else
{
e.Value = string.Empty;
}
break;
case "Accounts":
var accountIdList = e.Value.Split( ',' ).AsIntegerList();
if ( accountIdList.Any() )
{
var service = new FinancialAccountService( new RockContext() );
var accounts = service.GetByIds( accountIdList );
if ( accounts != null && accounts.Any() )
{
e.Value = accounts.Select( a => a.Name ).ToList().AsDelimited( "," );
}
else
{
e.Value = string.Empty;
}
}
else
{
e.Value = string.Empty;
}
break;
default:
e.Value = string.Empty;
break;
}
}
示例10: btnSend_Click
protected void btnSend_Click( object sender, EventArgs e )
{
var mergeObjects = new Dictionary<string, object>();
var url = LinkedPageUrl( "ConfirmationPage" );
if ( string.IsNullOrWhiteSpace( url ) )
{
url = ResolveRockUrl( "~/ConfirmAccount" );
}
mergeObjects.Add( "ConfirmAccountUrl", RootPath + url.TrimStart( new char[] { '/' } ) );
var personDictionaries = new List<IDictionary<string, object>>();
var personService = new PersonService();
var userLoginService = new UserLoginService();
foreach ( Person person in personService.GetByEmail( tbEmail.Text ) )
{
var users = new List<IDictionary<string,object>>();
foreach ( UserLogin user in userLoginService.GetByPersonId( person.Id ) )
{
if ( user.EntityType != null )
{
var component = AuthenticationContainer.GetComponent( user.EntityType.Name );
if ( component.ServiceType == AuthenticationServiceType.Internal )
{
users.Add( user.ToDictionary() );
}
}
}
if (users.Count > 0)
{
IDictionary<string,object> personDictionary = person.ToDictionary();
personDictionary.Add("Users", users.ToArray());
personDictionaries.Add( personDictionary );
}
}
if ( personDictionaries.Count > 0 )
{
mergeObjects.Add( "Persons", personDictionaries.ToArray() );
var recipients = new Dictionary<string, Dictionary<string, object>>();
recipients.Add( tbEmail.Text, mergeObjects );
Email email = new Email( GetAttributeValue( "EmailTemplate" ) );
email.Send( recipients );
pnlEntry.Visible = false;
pnlSuccess.Visible = true;
}
else
pnlWarning.Visible = true;
}
示例11: GetPersonFromForm
protected Person GetPersonFromForm(string formId)
{
AttributeValueService attributeValueService = new AttributeValueService(rockContext);
PersonService personService = new PersonService(rockContext);
PersonAliasService personAliasService = new PersonAliasService(rockContext);
var formAttribute = attributeValueService.Queryable().FirstOrDefault(a => a.Value == formId);
var person = personService.Queryable().FirstOrDefault(p => p.Id == formAttribute.EntityId);
return person;
}
示例12: btnSend_Click
/// <summary>
/// Handles the Click event of the btnSend 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 btnSend_Click( object sender, EventArgs e )
{
var url = LinkedPageUrl( "ConfirmationPage" );
if ( string.IsNullOrWhiteSpace( url ) )
{
url = ResolveRockUrl( "~/ConfirmAccount" );
}
var mergeObjects = GlobalAttributesCache.GetMergeFields( CurrentPerson );
mergeObjects.Add( "ConfirmAccountUrl", RootPath + url.TrimStart( new char[] { '/' } ) );
var results = new List<IDictionary<string, object>>();
var rockContext = new RockContext();
var personService = new PersonService( rockContext );
var userLoginService = new UserLoginService( rockContext );
foreach ( Person person in personService.GetByEmail( tbEmail.Text )
.Where( p => p.Users.Any()))
{
var users = new List<UserLogin>();
foreach ( UserLogin user in userLoginService.GetByPersonId( person.Id ) )
{
if ( user.EntityType != null )
{
var component = AuthenticationContainer.GetComponent( user.EntityType.Name );
if ( !component.RequiresRemoteAuthentication )
{
users.Add( user );
}
}
}
var resultsDictionary = new Dictionary<string, object>();
resultsDictionary.Add( "Person", person);
resultsDictionary.Add( "Users", users );
results.Add( resultsDictionary );
}
if ( results.Count > 0 )
{
mergeObjects.Add( "Results", results.ToArray() );
var recipients = new List<RecipientData>();
recipients.Add( new RecipientData( tbEmail.Text, mergeObjects ) );
Email.Send( GetAttributeValue( "EmailTemplate" ).AsGuid(), recipients, ResolveRockUrlIncludeRoot( "~/" ), ResolveRockUrlIncludeRoot( "~~/" ) );
pnlEntry.Visible = false;
pnlSuccess.Visible = true;
}
else
{
pnlWarning.Visible = true;
}
}
示例13: RunCommand
/// <summary>
/// Binds the grid.
/// </summary>
private void RunCommand()
{
gReport.CreatePreviewColumns( typeof( Person ) );
var service = new PersonService();
var people = service.Queryable().Where( p => p.LastName == "Turner" );
var parents = service.Transform( people, new Rock.Reporting.DataTransform.Person.ParentTransform() );
gReport.DataSource = parents.ToList();
gReport.DataBind();
}
示例14: gBusinessList_Delete
/// <summary>
/// Handles the Delete event of the gBusinessList control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param>
protected void gBusinessList_Delete( object sender, Rock.Web.UI.Controls.RowEventArgs e )
{
var rockContext = new RockContext();
PersonService service = new PersonService( rockContext );
Person business = service.Get( e.RowKeyId );
if ( business != null )
{
business.RecordStatusValueId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ) ).Id;
rockContext.SaveChanges();
}
BindGrid();
}
示例15: 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
{
var groupGuid = GetAttributeValue( "Group" ).AsGuidOrNull();
string personKey = PageParameter( "Person" );
if ( !groupGuid.HasValue )
{
ShowConfigError( "The 'Group' configuration for this block has not been set." );
}
else if ( string.IsNullOrWhiteSpace( personKey ) )
{
ShowError( "Missing Parameter Value" );
}
else
{
RockContext rockContext = new RockContext();
Person targetPerson = null;
targetPerson = new PersonService( rockContext ).GetByUrlEncodedKey( personKey );
if ( targetPerson == null )
{
ShowError( "We can't find a record in our system for you." );
}
else
{
GroupService groupService = new GroupService( rockContext );
Group group = groupService.Get( groupGuid.Value );
if ( group == null )
{
ShowConfigError( "The 'Group' configuration for this block is incorrect." );
}
else
{
AddOrUpdatePersonInGroup( targetPerson, group, rockContext );
}
}
}
}
catch ( System.FormatException )
{
ShowError( "Something is wrong with that link. Are you sure you copied it correctly?" );
}
catch ( SystemException ex )
{
ShowError( ex.Message );
}
}