本文整理汇总了C#中Rock.Model.AttributeValueService类的典型用法代码示例。如果您正苦于以下问题:C# AttributeValueService类的具体用法?C# AttributeValueService怎么用?C# AttributeValueService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeValueService类属于Rock.Model命名空间,在下文中一共展示了AttributeValueService类的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: MapActivityMinistry
/// <summary>
/// Maps the activity ministry.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapActivityMinistry( IQueryable<Row> tableData )
{
int groupEntityTypeId = EntityTypeCache.Read( "Rock.Model.Group" ).Id;
var attributeService = new AttributeService();
// Add an Attribute for the unique F1 Ministry Id
var ministryAttributeId = attributeService.Queryable().Where( a => a.EntityTypeId == groupEntityTypeId
&& a.Key == "F1MinistryId" ).Select( a => a.Id ).FirstOrDefault();
if ( ministryAttributeId == 0 )
{
var newMinistryAttribute = new Rock.Model.Attribute();
newMinistryAttribute.Key = "F1MinistryId";
newMinistryAttribute.Name = "F1 Ministry Id";
newMinistryAttribute.FieldTypeId = IntegerFieldTypeId;
newMinistryAttribute.EntityTypeId = groupEntityTypeId;
newMinistryAttribute.EntityTypeQualifierValue = string.Empty;
newMinistryAttribute.EntityTypeQualifierColumn = string.Empty;
newMinistryAttribute.Description = "The FellowshipOne identifier for the ministry that was imported";
newMinistryAttribute.DefaultValue = string.Empty;
newMinistryAttribute.IsMultiValue = false;
newMinistryAttribute.IsRequired = false;
newMinistryAttribute.Order = 0;
attributeService.Add( newMinistryAttribute, ImportPersonAlias );
attributeService.Save( newMinistryAttribute, ImportPersonAlias );
ministryAttributeId = newMinistryAttribute.Id;
}
// Get previously imported Ministries
var importedMinistries = new AttributeValueService().GetByAttributeId( ministryAttributeId )
.Select( av => new { RLCId = av.Value.AsType<int?>(), LocationId = av.EntityId } )
.ToDictionary( t => t.RLCId, t => t.LocationId );
foreach ( var row in tableData )
{
int? ministryId = row["Ministry_ID"] as int?;
if ( ministryId != null && !importedMinistries.ContainsKey( ministryId ) )
{
// Activity_ID
// Ministry_Name
// Activity_Name
// Ministry_Active
// Activity_Active
}
}
}
示例3: btnSubmit_OnClick
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
pnlOpportunities.Visible = true;
pnlSignature.Visible = false;
pnlSuccess.Visible = true;
AttributeValueService attributeValueService = new AttributeValueService(rockContext);
PersonService personService = new PersonService(rockContext);
List<Guid> personGuidList = new List<Guid>();
personGuidList.Add(_targetPerson.Guid);
var p = attributeValueService.GetByAttributeIdAndEntityId(906, _targetPerson.Id);
var p2 = attributeValueService.GetByAttributeIdAndEntityId(1434, _targetPerson.Id);
var personFromService = personService.GetByGuids(personGuidList).FirstOrDefault();
DateTime dateToSave = DateTime.Now.AddYears(CurrentYearAdd);
p.Value = dateToSave.ToString();
if (p2.Value.IsNullOrWhiteSpace())
{
p2.Value = dateToSave.Year.ToString();
}
else
{
if (!p2.Value.Contains(dateToSave.Year.ToString()))
{
p2.Value = p2.Value + "," + dateToSave.Year.ToString();
}
}
personFromService.ConnectionStatusValue.Value = "Partner";
personFromService.ConnectionStatusValueId = 65;
rockContext.SaveChanges();
LoadOpportunities();
if (GetAttributeValue("SendConfirmationEmail") == "True")
{
SendEmail(personFromService.Email, CurrentDateTime.Year.ToString() + " Partnership Covenant", rockContext);
}
}
示例4: GetUserPreference
/// <summary>
/// Returns a <see cref="Rock.Model.Person"/> user preference value by preference setting's key.
/// </summary>
/// <param name="person">The <see cref="Rock.Model.Person"/> to retrieve the preference value for.</param>
/// <param name="key">A <see cref="System.String"/> representing the key name of the preference setting.</param>
/// <returns>A list of <see cref="System.String"/> containing the values associated with the user's preference setting.</returns>
public static List<string> GetUserPreference( Person person, string key )
{
int? PersonEntityTypeId = Rock.Web.Cache.EntityTypeCache.Read( Person.USER_VALUE_ENTITY ).Id;
var rockContext = new Rock.Data.RockContext();
var attributeService = new Model.AttributeService( rockContext );
var attribute = attributeService.Get( PersonEntityTypeId, string.Empty, string.Empty, key );
if (attribute != null)
{
var attributeValueService = new Model.AttributeValueService( rockContext );
var attributeValues = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, person.Id);
if (attributeValues != null && attributeValues.Count() > 0)
return attributeValues.Select( v => v.Value).ToList();
}
return null;
}
示例5: GetValue
/// <summary>
/// Gets the Global Attribute values for the specified key.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public string GetValue( string key )
{
if ( AttributeValues.Keys.Contains( key ) )
{
return AttributeValues[key].Value;
}
else
{
var attributeCache = Attributes.FirstOrDefault(a => a.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
if ( attributeCache != null )
{
var attributeValue = new AttributeValueService().GetByAttributeIdAndEntityId( attributeCache.Id, null ).FirstOrDefault();
string value = ( attributeValue != null && !string.IsNullOrEmpty( attributeValue.Value ) ) ? attributeValue.Value : attributeCache.DefaultValue;
AttributeValues.Add( attributeCache.Key, new KeyValuePair<string, string>( attributeCache.Name, value ) );
return value;
}
return string.Empty;
}
}
示例6: GetEnvDataAsJson
/// <summary>
/// Returns the environment data as json.
/// </summary>
/// <returns>a JSON formatted string</returns>
public static string GetEnvDataAsJson( System.Web.HttpRequest request, string rockUrl )
{
var envData = new Dictionary<string, string>();
envData.Add( "AppRoot", rockUrl );
envData.Add( "Architecture", ( IntPtr.Size == 4 ) ? "32bit" : "64bit" );
envData.Add( "AspNetVersion", Environment.Version.ToString() );
envData.Add( "IisVersion", request.ServerVariables["SERVER_SOFTWARE"] );
envData.Add( "ServerOs", Environment.OSVersion.ToString() );
try { envData.Add( "SqlVersion", Rock.Data.DbService.ExecuteScaler( "SELECT SERVERPROPERTY('productversion')" ).ToString() ); }
catch {}
try
{
using ( var rockContext = new RockContext() )
{
var entityType = EntityTypeCache.Read( "Rock.Security.BackgroundCheck.ProtectMyMinistry", false, rockContext );
if ( entityType != null )
{
var pmmUserName = new AttributeValueService( rockContext )
.Queryable().AsNoTracking()
.Where( v =>
v.Attribute.EntityTypeId.HasValue &&
v.Attribute.EntityTypeId.Value == entityType.Id &&
v.Attribute.Key == "UserName" )
.Select( v => v.Value )
.FirstOrDefault();
if ( !string.IsNullOrWhiteSpace( pmmUserName ) )
{
envData.Add( "PMMUserName", pmmUserName );
}
}
}
}
catch { }
return envData.ToJson();
}
示例7: 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;
}
示例8: Execute
public void Execute(IJobExecutionContext context)
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
string livePlatformUrl = dataMap.GetString("Address") ?? "http://live.newpointe.org/api/v1/events/current";
//Check ChurchOnline Platform API to see if there is a live event
using (WebClient wc = new WebClient())
{
LivePlatformUrlJson = wc.DownloadString(livePlatformUrl);
}
dynamic isServiceLive = JsonConvert.DeserializeObject(LivePlatformUrlJson);
string isLive = isServiceLive.response.item.isLive.ToString();
// specify which attribute key we want to work with
var attributeKey = "LiveService"; //production
var attributeValueService = new AttributeValueService(rockContext);
// specify NULL as the EntityId since this is a GlobalAttribute
var globalAttributeValue = attributeValueService.GetGlobalAttributeValue(attributeKey);
if (globalAttributeValue != null)
{
// save updated value to database
globalAttributeValue.Value = isLive;
rockContext.SaveChanges();
// flush the attributeCache for this attribute so it gets reloaded from the database
//Rock.Web.Cache.AttributeCache.Flush();
// flush the GlobalAttributeCache since this attribute is a GlobalAttribute
Rock.Web.Cache.GlobalAttributesCache.Flush();
}
}
示例9: dlgSearch_SaveClick
/// <summary>
/// Handles the SaveClick event of the dlgSearch 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 dlgSearch_SaveClick( object sender, EventArgs e )
{
using ( var rockContext = new RockContext() )
{
var connectionRequestService = new ConnectionRequestService( rockContext );
var connectionRequest = connectionRequestService.Get( hfConnectionRequestId.ValueAsInt() );
if ( connectionRequest != null &&
connectionRequest.ConnectionOpportunity != null &&
connectionRequest.ConnectionOpportunity.ConnectionType != null )
{
var qrySearch = connectionRequest.ConnectionOpportunity.ConnectionType.ConnectionOpportunities.ToList();
if ( !string.IsNullOrWhiteSpace( 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();
}
var searchCampuses = cblCampus.SelectedValuesAsInt;
if ( searchCampuses.Count > 0 )
{
qrySearch = qrySearch.Where( o => o.ConnectionOpportunityCampuses.Any( c => searchCampuses.Contains( c.CampusId ) ) ).ToList();
}
// Filter query by any configured attribute filters
if ( SearchAttributes != null && SearchAttributes.Any() )
{
var attributeValueService = new AttributeValueService( rockContext );
var parameterExpression = attributeValueService.ParameterExpression;
foreach ( var attribute in SearchAttributes )
{
var filterControl = phAttributeFilters.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 );
qrySearch = qrySearch.Where( w => attributeValues.Select( v => v.EntityId ).Contains( w.Id ) ).ToList();
}
}
}
}
rptSearchResult.DataSource = qrySearch;
rptSearchResult.DataBind();
}
}
}
示例10: GetData
//.........这里部分代码省略.........
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 );
}
string title = gfFilter.GetUserPreference( "Title" );
if (!string.IsNullOrWhiteSpace(title))
{
itemQry = itemQry.Where( i => i.Title.Contains( title ) );
}
// 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, 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 );
itemQry = itemQry.Where( w => attributeValues.Select( v => v.EntityId ).Contains( w.Id ) );
}
}
}
}
var items = new List<ContentChannelItem>();
foreach ( var item in itemQry.ToList() )
{
if ( item.IsAuthorized( Rock.Security.Authorization.VIEW, CurrentPerson ) )
{
items.Add( item );
}
}
SortProperty sortProperty = gContentChannelItems.SortProperty;
if ( sortProperty != null )
{
items = items.AsQueryable().Sort( sortProperty ).ToList();
}
else
{
items = items.OrderByDescending( p => p.StartDateTime ).ToList();
}
gContentChannelItems.ObjectList = new Dictionary<string, object>();
items.ForEach( i => gContentChannelItems.ObjectList.Add( i.Id.ToString(), i ) );
gContentChannelItems.DataSource = items.Select( i => new
{
i.Id,
i.Guid,
i.Title,
i.StartDateTime,
i.ExpireDateTime,
i.Priority,
Status = DisplayStatus( i.Status ),
Occurrences = i.EventItemOccurrences.Any()
} ).ToList();
gContentChannelItems.DataBind();
lContentChannelItems.Text = selectedChannel.Name + " Items";
}
else
{
divItemPanel.Visible = false;
}
}
示例11: DeleteGroupAndMemberData
/// <summary>
/// Generic method to delete the members of a group and then the group.
/// </summary>
/// <param name="group">The group.</param>
/// <param name="rockContext">The rock context.</param>
/// <exception cref="System.InvalidOperationException">Unable to delete group: + group.Name</exception>
private void DeleteGroupAndMemberData( Group group, RockContext rockContext )
{
GroupService groupService = new GroupService( rockContext );
// delete addresses
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
if ( group.GroupLocations.Count > 0 )
{
foreach ( var groupLocations in group.GroupLocations.ToList() )
{
group.GroupLocations.Remove( groupLocations );
groupLocationService.Delete( groupLocations );
}
}
// delete members
var groupMemberService = new GroupMemberService( rockContext );
var members = group.Members;
foreach ( var member in members.ToList() )
{
group.Members.Remove( member );
groupMemberService.Delete( member );
}
// delete attribute values
group.LoadAttributes( rockContext );
if ( group.AttributeValues != null )
{
var attributeValueService = new AttributeValueService( rockContext );
foreach ( var entry in group.AttributeValues )
{
var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( entry.Value.AttributeId, group.Id );
if ( attributeValue != null )
{
attributeValueService.Delete( attributeValue );
}
}
}
// now delete the group
if ( groupService.Delete( group ) )
{
// ok
}
else
{
throw new InvalidOperationException( "Unable to delete group: " + group.Name );
}
}
示例12: 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);
//.........这里部分代码省略.........
示例13: 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 )
//.........这里部分代码省略.........
示例14: Read
/// <summary>
/// Returns Global Attributes from cache. If they are not already in cache, they
/// will be read and added to cache
/// </summary>
/// <returns></returns>
public static GlobalAttributesCache Read( RockContext rockContext = null )
{
string cacheKey = GlobalAttributesCache.CacheKey();
ObjectCache cache = MemoryCache.Default;
GlobalAttributesCache globalAttributes = cache[cacheKey] as GlobalAttributesCache;
if ( globalAttributes != null )
{
return globalAttributes;
}
else
{
globalAttributes = new GlobalAttributesCache();
globalAttributes.Attributes = new List<AttributeCache>();
globalAttributes.AttributeValues = new Dictionary<string, KeyValuePair<string, string>>();
rockContext = rockContext ?? new RockContext();
var attributeService = new Rock.Model.AttributeService( rockContext );
var attributeValueService = new Rock.Model.AttributeValueService( rockContext );
foreach ( Rock.Model.Attribute attribute in attributeService.GetGlobalAttributes() )
{
var attributeCache = AttributeCache.Read( attribute );
globalAttributes.Attributes.Add( attributeCache );
var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attribute.Id, null ).FirstOrDefault();
string value = ( attributeValue != null && !string.IsNullOrEmpty( attributeValue.Value ) ) ? attributeValue.Value : attributeCache.DefaultValue;
globalAttributes.AttributeValues.Add( attributeCache.Key, new KeyValuePair<string, string>( attributeCache.Name, value ) );
}
cache.Set( cacheKey, globalAttributes, new CacheItemPolicy() );
return globalAttributes;
}
}
示例15: 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 )
//.........这里部分代码省略.........