本文整理汇总了C#中Rock.Model.AttributeValueService.Queryable方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeValueService.Queryable方法的具体用法?C# AttributeValueService.Queryable怎么用?C# AttributeValueService.Queryable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeValueService
的用法示例。
在下文中一共展示了AttributeValueService.Queryable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: GetAttributeExpression
/// <summary>
/// Builds an expression for an attribute field
/// </summary>
/// <param name="serviceInstance">The service instance.</param>
/// <param name="parameterExpression">The parameter expression.</param>
/// <param name="entityField">The property.</param>
/// <param name="values">The values.</param>
/// <returns></returns>
public Expression GetAttributeExpression( IService serviceInstance, ParameterExpression parameterExpression, EntityField entityField, List<string> values )
{
ComparisonType comparisonType = ComparisonType.EqualTo;
var service = new AttributeValueService( (RockContext)serviceInstance.Context );
var attributeValues = service.Queryable().Where( v =>
v.Attribute.Guid == entityField.AttributeGuid &&
v.EntityId.HasValue &&
v.Value != string.Empty );
ParameterExpression attributeValueParameterExpression = Expression.Parameter( typeof( AttributeValue ), "v" );
var filterExpression = entityField.FieldType.Field.AttributeFilterExpression( entityField.FieldConfig, values, attributeValueParameterExpression );
if ( filterExpression != null )
{
attributeValues = attributeValues.Where( attributeValueParameterExpression, filterExpression, null );
}
IQueryable<int> ids = attributeValues.Select( v => v.EntityId.Value );
if ( ids != null )
{
MemberExpression propertyExpression = Expression.Property( parameterExpression, "Id" );
ConstantExpression idsExpression = Expression.Constant( ids.AsQueryable(), typeof( IQueryable<int> ) );
Expression expression = Expression.Call( typeof( Queryable ), "Contains", new Type[] { typeof( int ) }, idsExpression, propertyExpression );
if ( comparisonType == ComparisonType.NotEqualTo ||
comparisonType == ComparisonType.DoesNotContain ||
comparisonType == ComparisonType.IsBlank )
{
return Expression.Not( expression );
}
else
{
return expression;
}
}
return null;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var shapePageReference = new Rock.Web.PageReference(GetAttributeValue("SHAPEAssessmentPage"));
var discPageReference = new Rock.Web.PageReference(GetAttributeValue("DISCAssessmentPage"));
if (!string.IsNullOrWhiteSpace(PageParameter("FormId")))
{
//Load the person based on the FormId
var personInUrl = PageParameter("FormId");
SelectedPerson = GetPersonFromForm(personInUrl);
PersonEncodedKey = SelectedPerson.UrlEncodedKey;
}
else if (!string.IsNullOrWhiteSpace(PageParameter("PersonId")))
{
//Load the person based on the PersonId
SelectedPerson = GetPersonFromId(PageParameter("PersonId"));
PersonEncodedKey = SelectedPerson.UrlEncodedKey;
}
else if (CurrentPerson != null)
{
//Load the person based on the currently logged in person
SelectedPerson = CurrentPerson;
PersonEncodedKey = SelectedPerson.UrlEncodedKey;
}
else
{
//Show Error Message
nbNoPerson.Visible = true;
Response.Redirect(shapePageReference.BuildUrl(), true);
return;
}
// Load the attributes
AttributeValueService attributeValueService = new AttributeValueService(rockContext);
DefinedValueService definedValueService = new DefinedValueService(rockContext);
string spiritualGift1 = "";
string spiritualGift2 = "";
string spiritualGift3 = "";
string spiritualGift4 = "";
string heartCategories = "";
string heartCauses = "";
string heartPassion = "";
string ability1 = "";
string ability2 = "";
string people = "";
string places = "";
string events = "";
var spiritualGift1AttributeValue =
attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SpiritualGift1" && a.EntityId == SelectedPerson.Id);
// Redirect if they haven't taken the Assessment
if (spiritualGift1AttributeValue == null)
{
Response.Redirect(shapePageReference.BuildUrl(), true);
}
else
{
var spiritualGift2AttributeValue =
attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SpiritualGift2" && a.EntityId == SelectedPerson.Id);
var spiritualGift3AttributeValue =
attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SpiritualGift3" && a.EntityId == SelectedPerson.Id);
var spiritualGift4AttributeValue =
attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SpiritualGift4" && a.EntityId == SelectedPerson.Id);
var ability1AttributeValue =
attributeValueService
.Queryable().FirstOrDefault(a => a.Attribute.Key == "Ability1" && a.EntityId == SelectedPerson.Id);
var ability2AttributeValue =
attributeValueService
.Queryable().FirstOrDefault(a => a.Attribute.Key == "Ability2" && a.EntityId == SelectedPerson.Id);
var peopleAttributeValue = attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SHAPEPeople" && a.EntityId == SelectedPerson.Id);
var placesAttributeValue = attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SHAPEPlaces" && a.EntityId == SelectedPerson.Id);
var eventsAttributeValue = attributeValueService
.Queryable()
.FirstOrDefault(a => a.Attribute.Key == "SHAPEEvents" && a.EntityId == SelectedPerson.Id);
//.........这里部分代码省略.........
示例4: ShowResults
/// <summary>
/// Binds the grid.
/// </summary>
private void ShowResults()
{
// Get the group types that we're interested in
Guid? groupTypeGuid = GetAttributeValue( "GroupType" ).AsGuidOrNull();
if ( !groupTypeGuid.HasValue )
{
ShowError( "A valid Group Type is required." );
return;
}
gGroups.Columns[1].Visible = GetAttributeValue( "ShowDescription" ).AsBoolean();
gGroups.Columns[2].Visible = GetAttributeValue( "ShowSchedule" ).AsBoolean();
gGroups.Columns[3].Visible = GetAttributeValue( "ShowCount" ).AsBoolean();
gGroups.Columns[4].Visible = GetAttributeValue( "ShowAge" ).AsBoolean();
bool showProximity = GetAttributeValue( "ShowProximity" ).AsBoolean();
gGroups.Columns[5].Visible = showProximity; // Distance
// Get query of groups of the selected group type
var rockContext = new RockContext();
var groupService = new GroupService( rockContext );
var groupQry = groupService
.Queryable( "GroupLocations.Location" )
.Where( g => g.IsActive && g.GroupType.Guid.Equals( groupTypeGuid.Value ) && g.IsPublic );
var groupParameterExpression = groupService.ParameterExpression;
var schedulePropertyExpression = Expression.Property( groupParameterExpression, "Schedule" );
var dowFilterControl = phFilterControls.FindControl( "filter_dow" );
if ( dowFilterControl != null )
{
var field = FieldTypeCache.Read( Rock.SystemGuid.FieldType.DAY_OF_WEEK ).Field;
var filterValues = field.GetFilterValues( dowFilterControl, null, Rock.Reporting.FilterMode.SimpleFilter );
var expression = field.PropertyFilterExpression( null, filterValues, schedulePropertyExpression, "WeeklyDayOfWeek", typeof( DayOfWeek? ) );
groupQry = groupQry.Where( groupParameterExpression, expression, null );
}
var timeFilterControl = phFilterControls.FindControl( "filter_time" );
if ( timeFilterControl != null )
{
var field = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TIME ).Field;
var filterValues = field.GetFilterValues( timeFilterControl, null, Rock.Reporting.FilterMode.SimpleFilter );
var expression = field.PropertyFilterExpression( null, filterValues, schedulePropertyExpression, "WeeklyTimeOfDay", typeof( TimeSpan? ) );
groupQry = groupQry.Where( groupParameterExpression, expression, null );
}
// Filter query by any configured attribute filters
if ( AttributeFilters != null && AttributeFilters.Any() )
{
var attributeValueService = new AttributeValueService( rockContext );
var parameterExpression = attributeValueService.ParameterExpression;
foreach ( var attribute in AttributeFilters )
{
var filterControl = phFilterControls.FindControl( "filter_" + attribute.Id.ToString() );
if ( filterControl != null )
{
var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter );
var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression );
if ( expression != null )
{
var attributeValues = attributeValueService
.Queryable()
.Where( v => v.Attribute.Id == attribute.Id );
attributeValues = attributeValues.Where( parameterExpression, expression, null );
groupQry = groupQry.Where( w => attributeValues.Select( v => v.EntityId ).Contains( w.Id ) );
}
}
}
}
List<GroupLocation> fences = null;
List<Group> groups = null;
// Run query to get list of matching groups
SortProperty sortProperty = gGroups.SortProperty;
if ( sortProperty != null )
{
groups = groupQry.Sort( sortProperty ).ToList();
}
else
{
groups = groupQry.OrderBy( g => g.Name ).ToList();
}
int? fenceGroupTypeId = GetGroupTypeId( GetAttributeValue( "GeofencedGroupType" ).AsGuidOrNull() );
bool showMap = GetAttributeValue( "ShowMap" ).AsBoolean();
bool showFences = showMap && GetAttributeValue( "ShowFence" ).AsBoolean();
var distances = new Dictionary<int, double>();
// If we care where these groups are located...
if ( fenceGroupTypeId.HasValue || showMap || showProximity )
//.........这里部分代码省略.........
示例5: GetAttributeExpression
/// <summary>
/// Builds an expression for an attribute field
/// </summary>
/// <param name="serviceInstance">The service instance.</param>
/// <param name="parameterExpression">The parameter expression.</param>
/// <param name="entityField">The property.</param>
/// <param name="values">The values.</param>
/// <returns></returns>
public static Expression GetAttributeExpression( IService serviceInstance, ParameterExpression parameterExpression, EntityField entityField, List<string> values )
{
var service = new AttributeValueService( (RockContext)serviceInstance.Context );
var attributeValues = service.Queryable().Where( v =>
v.EntityId.HasValue &&
v.Value != string.Empty );
if ( entityField.AttributeGuid.HasValue )
{
attributeValues = attributeValues.Where( v => v.Attribute.Guid == entityField.AttributeGuid );
}
else
{
attributeValues = attributeValues.Where( v => v.Attribute.Key == entityField.Name && v.Attribute.FieldTypeId == entityField.FieldType.Id );
}
ParameterExpression attributeValueParameterExpression = Expression.Parameter( typeof( AttributeValue ), "v" );
// Determine the appropriate comparison type to use for this Expression.
// Attribute Value records only exist for Entities that have a value specified for the Attribute.
// Therefore, if the specified comparison works by excluding certain values we must invert our filter logic:
// first we find the Attribute Values that match those values and then we exclude the associated Entities from the result set.
var comparisonType = ComparisonType.EqualTo;
ComparisonType evaluatedComparisonType = comparisonType;
if ( values.Count >= 2 )
{
string comparisonValue = values[0];
if ( comparisonValue != "0" )
{
comparisonType = comparisonValue.ConvertToEnum<ComparisonType>( ComparisonType.EqualTo );
}
switch ( comparisonType )
{
case ComparisonType.DoesNotContain:
evaluatedComparisonType = ComparisonType.Contains;
break;
case ComparisonType.IsBlank:
evaluatedComparisonType = ComparisonType.IsNotBlank;
break;
case ComparisonType.LessThan:
evaluatedComparisonType = ComparisonType.GreaterThanOrEqualTo;
break;
case ComparisonType.LessThanOrEqualTo:
evaluatedComparisonType = ComparisonType.GreaterThan;
break;
case ComparisonType.NotEqualTo:
evaluatedComparisonType = ComparisonType.EqualTo;
break;
default:
evaluatedComparisonType = comparisonType;
break;
}
values[0] = evaluatedComparisonType.ToString();
}
var filterExpression = entityField.FieldType.Field.AttributeFilterExpression( entityField.FieldConfig, values, attributeValueParameterExpression );
if ( filterExpression != null )
{
attributeValues = attributeValues.Where( attributeValueParameterExpression, filterExpression, null );
}
IQueryable<int> ids = attributeValues.Select( v => v.EntityId.Value );
MemberExpression propertyExpression = Expression.Property( parameterExpression, "Id" );
ConstantExpression idsExpression = Expression.Constant( ids.AsQueryable(), typeof( IQueryable<int> ) );
Expression expression = Expression.Call( typeof( Queryable ), "Contains", new Type[] { typeof( int ) }, idsExpression, propertyExpression );
// If we have used an inverted comparison type for the evaluation, invert the Expression so that it excludes the matching Entities.
if ( comparisonType != evaluatedComparisonType )
{
return Expression.Not( expression );
}
else
{
return expression;
}
}
示例6: GetData
private void GetData()
{
var rockContext = new RockContext();
var itemService = new ContentChannelItemService(rockContext);
int personId = CurrentPerson != null ? CurrentPerson.Id : 0;
// Get all of the content channels
var allChannels = new ContentChannelService( rockContext ).Queryable( "ContentChannelType" )
.OrderBy( w => w.Name )
.ToList();
// Create variable for storing authorized channels and the count of active items
var channelCounts = new Dictionary<int, int>();
foreach ( var channel in allChannels )
{
if ( channel.IsAuthorized( Authorization.VIEW, CurrentPerson))
{
channelCounts.Add( channel.Id, 0);
}
}
// Get the pending approval item counts for each channel (if the channel requires approval)
itemService.Queryable()
.Where( i =>
channelCounts.Keys.Contains( i.ContentChannelId ) &&
i.Status == ContentChannelItemStatus.PendingApproval && i.ContentChannel.RequiresApproval )
.GroupBy( i => i.ContentChannelId )
.Select( i => new {
Id = i.Key,
Count = i.Count()
})
.ToList()
.ForEach( i => channelCounts[i.Id] = i.Count );
// Create a query to return channel, the count of items, and the selected class
var qry = allChannels
.Where( c => channelCounts.Keys.Contains( c.Id ) )
.Select( c => new
{
Channel = c,
Count = channelCounts[c.Id],
Class = ( SelectedChannelId.HasValue && SelectedChannelId.Value == c.Id ) ? "active" : ""
} );
// If displaying active only, update query to exclude those content channels without any items
if ( tglStatus.Checked )
{
qry = qry.Where( c => c.Count > 0 );
}
var contentChannels = qry.ToList();
rptChannels.DataSource = contentChannels;
rptChannels.DataBind();
ContentChannel selectedChannel = null;
if ( SelectedChannelId.HasValue )
{
selectedChannel = allChannels
.Where( w =>
w.Id == SelectedChannelId.Value &&
channelCounts.Keys.Contains( SelectedChannelId.Value ) )
.FirstOrDefault();
}
if ( selectedChannel != null && contentChannels.Count > 0 )
{
// show the content item panel
divItemPanel.Visible = true;
BindAttributes( selectedChannel );
AddDynamicControls( selectedChannel );
var itemQry = itemService.Queryable()
.Where( i => i.ContentChannelId == selectedChannel.Id );
var drp = new DateRangePicker();
drp.DelimitedValues = gfFilter.GetUserPreference( "Date Range" );
if ( drp.LowerValue.HasValue )
{
if ( selectedChannel.ContentChannelType.DateRangeType == ContentChannelDateType.SingleDate )
{
itemQry = itemQry.Where( i => i.StartDateTime >= drp.LowerValue.Value );
}
else
{
itemQry = itemQry.Where( i => i.ExpireDateTime.HasValue && i.ExpireDateTime.Value >= drp.LowerValue.Value );
}
}
if ( drp.UpperValue.HasValue )
{
DateTime upperDate = drp.UpperValue.Value.Date.AddDays( 1 );
itemQry = itemQry.Where( i => i.StartDateTime <= upperDate );
}
var status = gfFilter.GetUserPreference( "Status" ).ConvertToEnumOrNull<ContentChannelItemStatus>();
if ( status.HasValue )
{
itemQry = itemQry.Where( i => i.Status == status );
//.........这里部分代码省略.........
示例7: UpdateList
/// <summary>
/// Updates the list.
/// </summary>
private void UpdateList()
{
using ( var rockContext = new RockContext() )
{
var searchSelections = new Dictionary<string, string>();
var connectionTypeId = GetAttributeValue( "ConnectionTypeId" ).AsInteger();
var connectionType = new ConnectionTypeService( rockContext ).Get( connectionTypeId );
var connectionOpportunityService = new ConnectionOpportunityService( rockContext );
var qrySearch = connectionOpportunityService.Queryable().Where( a => a.ConnectionTypeId == connectionTypeId && a.IsActive == true ).ToList();
if ( GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
{
if ( !string.IsNullOrWhiteSpace( tbSearchName.Text ) )
{
searchSelections.Add( "tbSearchName", tbSearchName.Text );
var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues( true );
qrySearch = qrySearch.Where( o => searchTerms.Any( t => t.Contains( o.Name.ToLower() ) || o.Name.ToLower().Contains( t ) ) ).ToList();
}
}
if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
{
var searchCampuses = cblCampus.SelectedValuesAsInt;
if ( searchCampuses.Count > 0 )
{
searchSelections.Add( "cblCampus", searchCampuses.AsDelimited("|") );
qrySearch = qrySearch.Where( o => o.ConnectionOpportunityCampuses.Any( c => searchCampuses.Contains( c.CampusId ) ) ).ToList();
}
}
if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
{
// Filter query by any configured attribute filters
if ( AvailableAttributes != null && AvailableAttributes.Any() )
{
var attributeValueService = new AttributeValueService( rockContext );
var parameterExpression = attributeValueService.ParameterExpression;
foreach ( var attribute in AvailableAttributes )
{
string filterControlId = "filter_" + attribute.Id.ToString();
var filterControl = phAttributeFilters.FindControl( filterControlId );
if ( filterControl != null )
{
var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter );
var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression );
if ( expression != null )
{
searchSelections.Add( filterControlId, filterValues.ToJson() );
var attributeValues = attributeValueService
.Queryable()
.Where( v => v.Attribute.Id == attribute.Id );
attributeValues = attributeValues.Where( parameterExpression, expression, null );
qrySearch = qrySearch.Where( o => attributeValues.Select( v => v.EntityId ).Contains( o.Id ) ).ToList();
}
}
}
}
}
string sessionKey = string.Format( "ConnectionSearch_{0}", this.BlockId );
Session[sessionKey] = searchSelections;
var opportunities = qrySearch.OrderBy( s => s.PublicName ).ToList();
var mergeFields = new Dictionary<string, object>();
mergeFields.Add( "Opportunities", opportunities);
mergeFields.Add( "CurrentPerson", CurrentPerson );
var pageReference = new PageReference( GetAttributeValue( "DetailPage" ), null );
mergeFields.Add( "DetailPage", BuildDetailPageUrl(pageReference.BuildUrl()) );
lOutput.Text = GetAttributeValue( "LavaTemplate" ).ResolveMergeFields( mergeFields );
if ( GetAttributeValue( "SetPageTitle" ).AsBoolean() )
{
string pageTitle = "Connection";
RockPage.PageTitle = pageTitle;
RockPage.BrowserTitle = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
RockPage.Header.Title = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
}
// show debug info
if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
{
lDebug.Visible = true;
lDebug.Text = mergeFields.lavaDebugInfo();
}
}
}
示例8: Execute
/// <summary>
/// Job that will run quick SQL queries on a schedule.
///
/// Called by the <see cref="IScheduler" /> when a
/// <see cref="ITrigger" /> fires that is associated with
/// the <see cref="IJob" />.
/// </summary>
public virtual void Execute( IJobExecutionContext context )
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
Guid? entryWorkflowType = dataMap.GetString( "EraEntryWorkflow" ).AsGuidOrNull();
Guid? exitWorkflowType = dataMap.GetString( "EraExitWorkflow" ).AsGuidOrNull();
bool updateVisitDates = dataMap.GetBooleanValue( "SetVisitDates" );
var groupTypeList = dataMap.GetString( "GroupTypes" );
// configuration
//
// giving
int exitGivingCount = 1;
// attendance
int exitAttendanceCountShort = 1;
int exitAttendanceCountLong = 8;
// get era dataset from stored proc
var resultContext = new RockContext();
var eraAttribute = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_CURRENTLY_AN_ERA.AsGuid() );
var eraStartAttribute = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_START_DATE.AsGuid() );
var eraEndAttribute = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_END_DATE.AsGuid() );
resultContext.Database.CommandTimeout = 3600;
var results = resultContext.Database.SqlQuery<EraResult>( "spCrm_FamilyAnalyticsEraDataset" ).ToList();
int personEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
int attributeEntityTypeId = EntityTypeCache.Read( "Rock.Model.Attribute" ).Id;
int eraAttributeId = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_CURRENTLY_AN_ERA.AsGuid() ).Id;
int personAnalyticsCategoryId = CategoryCache.Read( SystemGuid.Category.HISTORY_PERSON_ANALYTICS.AsGuid() ).Id;
foreach (var result in results )
{
// create new rock context for each family (https://weblog.west-wind.com/posts/2014/Dec/21/Gotcha-Entity-Framework-gets-slow-in-long-Iteration-Loops)
RockContext updateContext = new RockContext();
var attributeValueService = new AttributeValueService( updateContext );
var historyService = new HistoryService( updateContext );
// if era ensure it still meets requirements
if ( result.IsEra )
{
if (result.ExitGiftCountDuration < exitGivingCount && result.ExitAttendanceCountDurationShort < exitAttendanceCountShort && result.ExitAttendanceCountDurationLong < exitAttendanceCountLong )
{
// exit era (delete attribute value from each person in family)
var family = new GroupService( updateContext ).Queryable( "Members, Members.Person" ).AsNoTracking().Where( m => m.Id == result.FamilyId ).FirstOrDefault();
if ( family != null ) {
foreach ( var person in family.Members.Select( m => m.Person ) ) {
// remove the era flag
var eraAttributeValue = attributeValueService.Queryable().Where( v => v.AttributeId == eraAttribute.Id && v.EntityId == person.Id ).FirstOrDefault();
if ( eraAttributeValue != null )
{
attributeValueService.Delete( eraAttributeValue );
}
// set end date
var eraEndAttributeValue = attributeValueService.Queryable().Where( v => v.AttributeId == eraEndAttribute.Id && v.EntityId == person.Id ).FirstOrDefault();
if ( eraEndAttributeValue == null )
{
eraEndAttributeValue = new AttributeValue();
eraEndAttributeValue.EntityId = person.Id;
eraEndAttributeValue.AttributeId = eraEndAttribute.Id;
attributeValueService.Add( eraEndAttributeValue );
}
eraEndAttributeValue.Value = RockDateTime.Now.ToString();
// add a history record
if ( personAnalyticsCategoryId != 0 && personEntityTypeId != 0 && attributeEntityTypeId != 0 && eraAttributeId != 0 )
{
History historyRecord = new History();
historyService.Add( historyRecord );
historyRecord.EntityTypeId = personEntityTypeId;
historyRecord.EntityId = person.Id;
historyRecord.CreatedDateTime = RockDateTime.Now;
historyRecord.CreatedByPersonAliasId = person.PrimaryAliasId;
historyRecord.Caption = "eRA";
historyRecord.Summary = "Exited eRA Status";
historyRecord.Verb = "EXITED";
historyRecord.RelatedEntityTypeId = attributeEntityTypeId;
historyRecord.RelatedEntityId = eraAttributeId;
historyRecord.CategoryId = personAnalyticsCategoryId;
}
updateContext.SaveChanges();
}
// launch exit workflow
if ( exitWorkflowType.HasValue )
//.........这里部分代码省略.........
示例9: BindGroupMembersGrid
/// <summary>
/// Binds the group members grid.
/// </summary>
protected void BindGroupMembersGrid( bool isExporting = false )
{
if ( _group != null )
{
pnlGroupMembers.Visible = true;
lHeading.Text = string.Format( "{0} {1}", _group.GroupType.GroupTerm, _group.GroupType.GroupMemberTerm.Pluralize() );
if ( _group.GroupType.Roles.Any() )
{
nbRoleWarning.Visible = false;
rFilter.Visible = true;
gGroupMembers.Visible = true;
var rockContext = new RockContext();
if ( _group != null &&
_group.RequiredSignatureDocumentTemplateId.HasValue )
{
Signers = new SignatureDocumentService( rockContext )
.Queryable().AsNoTracking()
.Where( d =>
d.SignatureDocumentTemplateId == _group.RequiredSignatureDocumentTemplateId.Value &&
d.Status == SignatureDocumentStatus.Signed &&
d.BinaryFileId.HasValue &&
d.AppliesToPersonAlias != null )
.OrderByDescending( d => d.LastStatusDate )
.Select( d => d.AppliesToPersonAlias.PersonId )
.ToList();
}
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
var qry = groupMemberService.Queryable( "Person,GroupRole", true ).AsNoTracking()
.Where( m => m.GroupId == _group.Id );
// Filter by First Name
string firstName = tbFirstName.Text;
if ( !string.IsNullOrWhiteSpace( firstName ) )
{
qry = qry.Where( m =>
m.Person.FirstName.StartsWith( firstName ) ||
m.Person.NickName.StartsWith( firstName ) );
}
// Filter by Last Name
string lastName = tbLastName.Text;
if ( !string.IsNullOrWhiteSpace( lastName ) )
{
qry = qry.Where( m => m.Person.LastName.StartsWith( lastName ) );
}
// Filter by role
var validGroupTypeRoles = _group.GroupType.Roles.Select( r => r.Id ).ToList();
var roles = new List<int>();
foreach ( var roleId in cblRole.SelectedValues.AsIntegerList() )
{
if ( validGroupTypeRoles.Contains( roleId ) )
{
roles.Add( roleId );
}
}
if ( roles.Any() )
{
qry = qry.Where( m => roles.Contains( m.GroupRoleId ) );
}
// Filter by Group Member Status
var statuses = new List<GroupMemberStatus>();
foreach ( string status in cblGroupMemberStatus.SelectedValues )
{
if ( !string.IsNullOrWhiteSpace( status ) )
{
statuses.Add( status.ConvertToEnum<GroupMemberStatus>() );
}
}
if ( statuses.Any() )
{
qry = qry.Where( m => statuses.Contains( m.GroupMemberStatus ) );
}
var genders = new List<Gender>();
foreach ( var item in cblGenderFilter.SelectedValues )
{
var gender = item.ConvertToEnum<Gender>();
genders.Add( gender );
}
if ( genders.Any() )
{
qry = qry.Where( m => genders.Contains( m.Person.Gender ) );
}
// Filter by Campus
if ( cpCampusFilter.SelectedCampusId.HasValue )
{
//.........这里部分代码省略.........
示例10: ProcessConfirmation
//.........这里部分代码省略.........
return false;
}
}
tdTransactionCodeReceipt.Description = TransactionCode;
tdTransactionCodeReceipt.Visible = !string.IsNullOrWhiteSpace( TransactionCode );
tdScheduleId.Description = ScheduleId;
tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId );
tdNameReceipt.Description = paymentInfo.FullName;
tdPhoneReceipt.Description = paymentInfo.Phone;
tdEmailReceipt.Description = paymentInfo.Email;
tdAddressReceipt.Description = string.Format( "{0} {1}, {2} {3}", paymentInfo.Street1, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode );
rptAccountListReceipt.DataSource = SelectedAccounts.Where( a => a.Amount != 0 );
rptAccountListReceipt.DataBind();
tdTotalReceipt.Description = paymentInfo.Amount.ToString( "C" );
tdPaymentMethodReceipt.Description = paymentInfo.CurrencyTypeValue.Description;
tdAccountNumberReceipt.Description = paymentInfo.MaskedNumber;
tdWhenReceipt.Description = schedule != null ? schedule.ToString() : "Today";
// If there was a transaction code returned and this was not already created from a previous saved account,
// show the option to save the account.
if ( !( paymentInfo is ReferencePaymentInfo ) && !string.IsNullOrWhiteSpace( TransactionCode ) && gateway.SupportsSavedAccount( paymentInfo.CurrencyTypeValue ) )
{
cbSaveAccount.Visible = true;
pnlSaveAccount.Visible = true;
txtSaveAccount.Visible = true;
// If current person does not have a login, have them create a username and password
phCreateLogin.Visible = !new UserLoginService( rockContext ).GetByPersonId( person.Id ).Any();
}
else if ( !new UserLoginService( rockContext ).GetByPersonId( person.Id ).Any() )
{
pnlSaveAccount.Visible = true;
phCreateLogin.Visible = true;
cbSaveAccount.Visible = false;
txtSaveAccount.Visible = false;
}
else
{
pnlSaveAccount.Visible = false;
}
if ( PageParameter( "argsd" ) == "1" )
{
var rc = new RockContext();
var ats = new AttributeService( rc );
var argsd = ats.Queryable().Where( x => x.Key == "AutomatedRecurringGiftSetupDate" ).FirstOrDefault();
if ( argsd == null )
{
argsd = new Rock.Model.Attribute();
argsd.FieldTypeId = 85;
argsd.EntityTypeId = 15;
argsd.Key = "AutomatedRecurringGiftSetupDate";
argsd.Name = "Automated Recurring Gift Setup Date";
argsd.Guid = Guid.NewGuid();
argsd.CreatedDateTime = argsd.ModifiedDateTime = DateTime.Now;
ats.Add( argsd );
rc.SaveChanges();
rc = new RockContext();
ats = new AttributeService( rc );
argsd = ats.Queryable().Where( x => x.Key == "AutomatedRecurringGiftSetupDate" ).FirstOrDefault();
}
if ( argsd != null )
{
var atvs = new AttributeValueService( rc );
var argsdVal = atvs.Queryable().Where( x => x.AttributeId == argsd.Id && x.EntityId == person.Id ).FirstOrDefault();
if ( argsdVal == null )
{
argsdVal = new Rock.Model.AttributeValue();
argsdVal.AttributeId = argsd.Id;
argsdVal.EntityId = person.Id;
argsdVal.Value = DateTime.Now.ToString( "o" );
argsdVal.Guid = Guid.NewGuid();
argsdVal.CreatedDateTime = argsdVal.ModifiedDateTime = DateTime.Now;
atvs.Add( argsdVal );
rc.SaveChanges();
}
else
{
argsdVal.Value = DateTime.Now.ToString( "o" );
rc.SaveChanges();
}
}
}
return true;
}
else
{
pnlDupWarning.Visible = true;
divActions.Visible = false;
errorMessage = string.Empty;
return false;
}
}
示例11: MapIndividualGiftedness
/// <summary>
/// Maps the Individual Giftedness.
/// </summary>
/// <param name="tableData">The table data.</param>
private void MapIndividualGiftedness( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
var attributeService = new AttributeService( lookupContext );
int rank1Id = attributeService.Queryable().Where( a => a.Key == "Rank1" ).FirstOrDefault().Id;
int rank2Id = attributeService.Queryable().Where( a => a.Key == "Rank2" ).FirstOrDefault().Id;
int rank3Id = attributeService.Queryable().Where( a => a.Key == "Rank3" ).FirstOrDefault().Id;
int rank4Id = attributeService.Queryable().Where( a => a.Key == "Rank4" ).FirstOrDefault().Id;
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying Giftedness Program import ({0:N0} found).", totalRows ) );
var newAttributeValueList = new List<AttributeValue>();
foreach ( var row in tableData )
{
int? individualId = row["Individual_ID"] as int?;
int personId = (int)GetPersonAliasId( individualId );
var newAttributeValue = new AttributeValue();
int? rank = row["Rank"] as int?;
int rankId = 0;
//not everyone has all 4 ranks, some are missing the fourth and that was causing it to run in the below if condition and try to create a duplicate record.
if ( rank == 1 ) { rankId = rank1Id; }
if ( rank == 2 ) { rankId = rank2Id; }
if ( rank == 3 ) { rankId = rank3Id; }
if ( rank == 4 ) { rankId = rank4Id; }
if ( personId != 0 && rankId != 0 )
{
var attributeValueService = new AttributeValueService( lookupContext );
//checks if they are in the database already or if there is a record currently in the newAttributeValueList
if ( attributeValueService.Queryable().Where( a => a.AttributeId == rankId && a.EntityId == personId ).FirstOrDefault() == null && newAttributeValueList.Find(a => a.AttributeId == rankId && a.EntityId == personId) == null )
{
DateTime? assessmentDate = row["AssessmentDate"] as DateTime?;
int? giftAttributeId = row["GiftAttributeID"] as int?;
string giftAttributeIdString = Convert.ToString( giftAttributeId );
var definedValueService = new DefinedValueService( lookupContext );
newAttributeValue.IsSystem = false;
newAttributeValue.EntityId = personId;
if ( rank == 1 ) { newAttributeValue.AttributeId = rank1Id; }
if ( rank == 2 ) { newAttributeValue.AttributeId = rank2Id; }
if ( rank == 3 ) { newAttributeValue.AttributeId = rank3Id; }
if ( rank == 4 ) { newAttributeValue.AttributeId = rank4Id; }
newAttributeValue.Value = Convert.ToString( definedValueService.Queryable().Where( a => a.ForeignId == giftAttributeIdString ).FirstOrDefault().Guid );
newAttributeValue.CreatedDateTime = assessmentDate;
newAttributeValueList.Add( newAttributeValue );
completed++;
}
}
if ( newAttributeValueList.Any() )
{
if ( completed % percentage < 1 )
{
int percentComplete = completed / percentage;
ReportProgress( percentComplete, string.Format( "{0:N0} spiritual gifts imported ({1}% complete).", completed, percentComplete ) );
}
else if ( completed % ReportingNumber < 1 )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.AttributeValues.AddRange( newAttributeValueList );
rockContext.SaveChanges( DisableAudit );
newAttributeValueList.Clear();
} );
ReportPartialProgress();
}
}
}
if ( newAttributeValueList.Any() )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.AttributeValues.AddRange( newAttributeValueList );
rockContext.SaveChanges( DisableAudit );
} );
}
ReportProgress( 100, string.Format( "Finished individual gifts import: {0:N0} spiritual gifts imported.", completed ) );
}
示例12: lvAttributeValues_ItemInserting
void lvAttributeValues_ItemInserting( object sender, ListViewInsertEventArgs e )
{
PlaceHolder phInsertValue = lvAttributeValues.InsertItem.FindControl( "phInsertValue" ) as PlaceHolder;
if ( phInsertValue != null && phInsertValue.Controls.Count == 1 )
{
string value = _attribute.FieldType.Field.GetEditValue( phInsertValue.Controls[0], _attribute.QualifierValues );
var attributeValueService = new AttributeValueService();
var attributeValue = new AttributeValue();
attributeValue.AttributeId = _attribute.Id;
attributeValue.EntityId = _model.Id;
attributeValue.Value = value;
int? maxOrder = attributeValueService.Queryable().
Where( a => a.AttributeId == attributeValue.AttributeId &&
a.EntityId == attributeValue.EntityId).
Select( a => ( int? )a.Order ).Max();
attributeValue.Order = maxOrder.HasValue ? maxOrder.Value + 1 : 0;
attributeValueService.Add( attributeValue, _currentPersonId);
attributeValueService.Save( attributeValue, _currentPersonId );
_model.LoadAttributes();
}
lvAttributeValues.EditIndex = -1;
BindData();
}
示例13: BindGroupMembersGrid
/// <summary>
/// Binds the group members grid.
/// </summary>
protected void BindGroupMembersGrid()
{
if ( _group != null )
{
pnlGroupMembers.Visible = true;
lHeading.Text = string.Format( "{0} {1}", _group.GroupType.GroupTerm, _group.GroupType.GroupMemberTerm.Pluralize() );
if ( _group.GroupType.Roles.Any() )
{
nbRoleWarning.Visible = false;
rFilter.Visible = true;
gGroupMembers.Visible = true;
var rockContext = new RockContext();
GroupMemberService groupMemberService = new GroupMemberService( rockContext );
var qry = groupMemberService.Queryable( "Person,GroupRole", true )
.Where( m => m.GroupId == _group.Id );
// Filter by First Name
string firstName = tbFirstName.Text;
if ( !string.IsNullOrWhiteSpace( firstName ) )
{
qry = qry.Where( m => m.Person.FirstName.StartsWith( firstName ) );
}
// Filter by Last Name
string lastName = tbLastName.Text;
if ( !string.IsNullOrWhiteSpace( lastName ) )
{
qry = qry.Where( m => m.Person.LastName.StartsWith( lastName ) );
}
// Filter by role
var validGroupTypeRoles = _group.GroupType.Roles.Select( r => r.Id ).ToList();
var roles = new List<int>();
foreach ( string role in cblRole.SelectedValues )
{
if ( !string.IsNullOrWhiteSpace( role ) )
{
int roleId = int.MinValue;
if ( int.TryParse( role, out roleId ) && validGroupTypeRoles.Contains( roleId ) )
{
roles.Add( roleId );
}
}
}
if ( roles.Any() )
{
qry = qry.Where( m => roles.Contains( m.GroupRoleId ) );
}
// Filter by Status
var statuses = new List<GroupMemberStatus>();
foreach ( string status in cblStatus.SelectedValues )
{
if ( !string.IsNullOrWhiteSpace( status ) )
{
statuses.Add( status.ConvertToEnum<GroupMemberStatus>() );
}
}
if ( statuses.Any() )
{
qry = qry.Where( m => statuses.Contains( m.GroupMemberStatus ) );
}
// Filter query by any configured attribute filters
if ( AvailableAttributes != null && AvailableAttributes.Any() )
{
var attributeValueService = new AttributeValueService( rockContext );
var parameterExpression = attributeValueService.ParameterExpression;
foreach ( var attribute in AvailableAttributes )
{
var filterControl = phAttributeFilters.FindControl( "filter_" + attribute.Id.ToString() );
if ( filterControl != null )
{
var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues );
var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression );
if ( expression != null )
{
var attributeValues = attributeValueService
.Queryable()
.Where( v => v.Attribute.Id == attribute.Id );
attributeValues = attributeValues.Where( parameterExpression, expression, null );
qry = qry.Where( w => attributeValues.Select( v => v.EntityId ).Contains( w.Id ) );
}
}
}
}
_inactiveStatus = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE );
SortProperty sortProperty = gGroupMembers.SortProperty;
//.........这里部分代码省略.........
示例14: GetSettings
/// <summary>
/// Gets the settings.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
private List<AttributeValue> GetSettings( RockContext rockContext )
{
var pmmEntityType = EntityTypeCache.Read( typeof( Rock.Security.BackgroundCheck.ProtectMyMinistry ) );
if ( pmmEntityType != null )
{
var service = new AttributeValueService( rockContext );
return service.Queryable( "Attribute" )
.Where( v => v.Attribute.EntityTypeId == pmmEntityType.Id )
.ToList();
}
return null;
}
示例15: LoadAttributes
/// <summary>
/// Loads the <see cref="P:IHasAttributes.Attributes" /> and <see cref="P:IHasAttributes.AttributeValues" /> of any <see cref="IHasAttributes" /> object
/// </summary>
/// <param name="entity">The item.</param>
/// <param name="rockContext">The rock context.</param>
public static void LoadAttributes( Rock.Attribute.IHasAttributes entity, RockContext rockContext )
{
if ( entity != null )
{
Dictionary<string, PropertyInfo> properties = new Dictionary<string, PropertyInfo>();
Type entityType = entity.GetType();
if ( entityType.Namespace == "System.Data.Entity.DynamicProxies" )
entityType = entityType.BaseType;
rockContext = rockContext ?? new RockContext();
// Check for group type attributes
var groupTypeIds = new List<int>();
if ( entity is GroupMember || entity is Group || entity is GroupType )
{
// Can't use GroupTypeCache here since it loads attributes and would result in a recursive stack overflow situation
var groupTypeService = new GroupTypeService( rockContext );
GroupType groupType = null;
if ( entity is GroupMember )
{
var group = ( (GroupMember)entity ).Group ?? new GroupService( rockContext )
.Queryable().AsNoTracking().FirstOrDefault(g => g.Id == ( (GroupMember)entity ).GroupId );
if ( group != null )
{
groupType = group.GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == group.GroupTypeId );
}
}
else if ( entity is Group )
{
groupType = ( (Group)entity ).GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( (Group)entity ).GroupTypeId );
}
else
{
groupType = ( (GroupType)entity );
}
while ( groupType != null )
{
groupTypeIds.Insert( 0, groupType.Id );
// Check for inherited group type id's
if ( groupType.InheritedGroupTypeId.HasValue )
{
groupType = groupType.InheritedGroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( groupType.InheritedGroupTypeId ?? 0 ) );
}
else
{
groupType = null;
}
}
}
foreach ( PropertyInfo propertyInfo in entityType.GetProperties() )
properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
Rock.Model.AttributeService attributeService = new Rock.Model.AttributeService( rockContext );
Rock.Model.AttributeValueService attributeValueService = new Rock.Model.AttributeValueService( rockContext );
var inheritedAttributes = new Dictionary<int, List<Rock.Web.Cache.AttributeCache>>();
if ( groupTypeIds.Any() )
{
groupTypeIds.ForEach( g => inheritedAttributes.Add( g, new List<Rock.Web.Cache.AttributeCache>() ) );
}
else
{
inheritedAttributes.Add( 0, new List<Rock.Web.Cache.AttributeCache>() );
}
var attributes = new List<Rock.Web.Cache.AttributeCache>();
// Get all the attributes that apply to this entity type and this entity's properties match any attribute qualifiers
var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( entityType);
if ( entityTypeCache != null )
{
int entityTypeId = entityTypeCache.Id;
foreach ( var attribute in attributeService.Queryable()
.AsNoTracking()
.Where( a => a.EntityTypeId == entityTypeCache.Id )
.Select( a => new
{
a.Id,
a.EntityTypeQualifierColumn,
a.EntityTypeQualifierValue
}
) )
{
// group type ids exist (entity is either GroupMember, Group, or GroupType) and qualifier is for a group type id
if ( groupTypeIds.Any() && (
( entity is GroupMember && string.Compare( attribute.EntityTypeQualifierColumn, "GroupTypeId", true ) == 0 ) ||
//.........这里部分代码省略.........