本文整理汇总了C#中Rock.Model.AttributeValueService.GetGlobalAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeValueService.GetGlobalAttributeValue方法的具体用法?C# AttributeValueService.GetGlobalAttributeValue怎么用?C# AttributeValueService.GetGlobalAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeValueService
的用法示例。
在下文中一共展示了AttributeValueService.GetGlobalAttributeValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <param name="saveValue">if set to <c>true</c> [save value].</param>
/// <param name="rockContext">The rock context.</param>
public void SetValue( string key, string value, bool saveValue, RockContext rockContext = null )
{
if ( saveValue )
{
if ( rockContext == null )
{
rockContext = new RockContext();
}
// Save new value
var attributeValueService = new AttributeValueService( rockContext );
var attributeValue = attributeValueService.GetGlobalAttributeValue( key );
if ( attributeValue == null )
{
var attributeService = new AttributeService( rockContext );
var attribute = attributeService.GetGlobalAttribute( key );
if ( attribute == null )
{
attribute = new Rock.Model.Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
attribute.EntityTypeQualifierColumn = string.Empty;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key.SplitCase();
attributeService.Add( attribute );
rockContext.SaveChanges();
Attributes.Add( AttributeCache.Read( attribute.Id ) );
}
attributeValue = new AttributeValue();
attributeValueService.Add( attributeValue );
attributeValue.IsSystem = false;
attributeValue.AttributeId = attribute.Id;
if ( !AttributeValues.Keys.Contains( key ) )
{
AttributeValues.Add( key, new KeyValuePair<string, string>( attribute.Name, value ) );
}
}
attributeValue.Value = value;
rockContext.SaveChanges();
}
var attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
if ( attributeCache != null ) // (Should never be null)
{
if ( AttributeValues.Keys.Contains( key ) )
{
AttributeValues[key] = new KeyValuePair<string, string>( attributeCache.Name, value );
}
else
{
AttributeValues.Add( key, new KeyValuePair<string, string>( attributeCache.Name, value ) );
}
}
}
示例3: CalulateMetrics
protected void CalulateMetrics(int CampusId)
{
// specify which attribute key we want to work with
var attributeKeyCompositeUseGlobalValue = "CompositeUseGlobalValue";
var attributeKeyCompositeGoalMultiplier = "CompositeGoalMultiplier";
var attributeValueService = new AttributeValueService(rockContext);
// specify NULL as the EntityId since this is a GlobalAttribute
var compositeUseGlobalValue = attributeValueService.GetGlobalAttributeValue(attributeKeyCompositeUseGlobalValue);
var compositeGoalMultiplier = attributeValueService.GetGlobalAttributeValue(attributeKeyCompositeGoalMultiplier);
if (bool.Parse(compositeUseGlobalValue.ToString()) == true)
{
UseGlobalAttributeGoal = true;
GoalMultiplier = Convert.ToDouble(compositeGoalMultiplier.ToString());
}
//Set Last Sunday Date
DateTime now = DateTime.Now;
DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Sunday);
SundayDate = dt.ToShortDateString();
SundayDateSQLFormatted = dt.Date.ToString("yyyy-MM-dd");
DateTime lastTuesday = DateTime.Now.AddDays(-1);
while (lastTuesday.DayOfWeek != DayOfWeek.Wednesday)
lastTuesday = lastTuesday.AddDays(-1);
DateTime lastWednesday = DateTime.Now.AddDays(-1);
while (lastWednesday.DayOfWeek != DayOfWeek.Wednesday)
lastWednesday = lastWednesday.AddDays(-1);
FinancialStartDate = lastTuesday.AddDays(-7).ToString("yyyy-MM-dd");
FinancialEndDate = lastWednesday.ToString("yyyy-MM-dd");
FinancialStartDateLastWeek = lastTuesday.AddDays(-14).ToString("yyyy-MM-dd");
FinancialEndDateLastWeek = lastWednesday.AddDays(-7).ToString("yyyy-MM-dd");
sMonth = DateTime.Now.Month.ToString();
sYear = DateTime.Now.Year.ToString();
int iMonth = Int32.Parse(sMonth);
int iYear = Int32.Parse(sYear);
int lastDayOfCurrentMonth = DateTime.DaysInMonth(iYear, iMonth);
int lastDayOfLastMonth = DateTime.DaysInMonth(iYear, iMonth - 1);
DateTime fiscalYearStartDate = new DateTime(iYear, 9, 1);
DateTime fiscalYearEndDate = new DateTime(iYear + 1, 8, 31);
DateTime lastFiscalYearStartDate = new DateTime(iYear - 1, 9, 1);
DateTime lastFiscalYearEndDate = new DateTime(iYear, 8, 31);
DateTime start2020 = new DateTime(2020, 1, 1);
DateTime end2020 = new DateTime(2020, 12, 31);
if (iMonth < 9)
{
fiscalYearStartDate = fiscalYearStartDate.AddYears(-1);
fiscalYearEndDate = fiscalYearEndDate.AddYears(-1);
lastFiscalYearStartDate = lastFiscalYearStartDate.AddYears(-1);
lastFiscalYearEndDate = lastFiscalYearEndDate.AddYears(-1);
}
DateTime periodEndDate = new DateTime(iYear, iMonth - 1, lastDayOfLastMonth);
DateTime lastPeriodEndDate = new DateTime(iYear - 1, iMonth - 1, lastDayOfLastMonth);
FiscalYearStartDate = fiscalYearStartDate.ToShortDateString();
FiscalYearEndDate = fiscalYearEndDate.ToShortDateString();
PeriodStartDate = fiscalYearStartDate.ToShortDateString();
PeriodEndDate = periodEndDate.ToShortDateString();
LastPeriodStartDate = lastFiscalYearStartDate.ToShortDateString();
LastPeriodEndDate = lastPeriodEndDate.ToShortDateString();
Last8WkStartDate = now.AddDays(-57).ToShortDateString();
Last8WkEndDate = now.ToShortDateString();
Last8WkStartDateLy = now.AddDays(-57).AddYears(-1).ToShortDateString();
Last8WkEndDateLy = now.AddYears(-1).ToShortDateString();
Last6WkStartDate = now.AddDays(-43).ToShortDateString();
Last6WkEndDate = now.ToShortDateString();
Last6WkStartDateLy = now.AddDays(-43).AddYears(-1).ToShortDateString();
Last6WkEndDateLy = now.AddYears(-1).ToShortDateString();
DateTime last6WkStartDate = now.AddDays(-43);
DateTime last6WkEndDate = now;
DateTime last6WkStartDateLy = now.AddDays(-43).AddYears(-1);
DateTime last6WkEndDateLy = now.AddYears(-1);
switch (iMonth)
{
case 09:
CurrentMonthInFiscalYear = 1;
GoalOffsetMultiplier = .083;
SecondaryGoalOffsetMultiplier = .89;
break;
case 10:
CurrentMonthInFiscalYear = 2;
GoalOffsetMultiplier = .167;
SecondaryGoalOffsetMultiplier = .90;
break;
case 11:
//.........这里部分代码省略.........
示例4: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <param name="saveValue">if set to <c>true</c> [save value].</param>
/// <param name="rockContext">The rock context.</param>
public void SetValue( string key, string value, bool saveValue, RockContext rockContext )
{
AttributeCache attributeCache = null;
if ( saveValue )
{
// Save new value
rockContext = rockContext ?? new RockContext();
var attributeValueService = new AttributeValueService( rockContext );
var attributeValue = attributeValueService.GetGlobalAttributeValue( key );
if ( attributeValue == null )
{
var attributeService = new AttributeService( rockContext );
var attribute = attributeService.GetGlobalAttribute( key );
if ( attribute == null )
{
attribute = new Rock.Model.Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
attribute.EntityTypeQualifierColumn = string.Empty;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key.SplitCase();
attributeService.Add( attribute );
rockContext.SaveChanges();
}
attributeValue = new AttributeValue();
attributeValue.IsSystem = false;
attributeValue.AttributeId = attribute.Id;
attributeValueService.Add( attributeValue );
}
attributeValue.Value = value;
rockContext.SaveChanges();
}
lock(_obj)
{
attributeIds = null;
}
AttributeValues.AddOrUpdate( key, value, ( k, v ) => value );
attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
if ( attributeCache != null )
{
value = attributeCache.FieldType.Field.FormatValue( null, value, attributeCache.QualifierValues, false );
}
AttributeValuesFormatted.AddOrUpdate( key, value, (k, v) => value);
}