本文整理汇总了C#中Rock.Model.DefinedValueService.GetByGuid方法的典型用法代码示例。如果您正苦于以下问题:C# DefinedValueService.GetByGuid方法的具体用法?C# DefinedValueService.GetByGuid怎么用?C# DefinedValueService.GetByGuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.DefinedValueService
的用法示例。
在下文中一共展示了DefinedValueService.GetByGuid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
{
errorMessages = new List<string>();
// Get person
Person person = null;
int personAliasId = 1;
string personAttributeValue = GetAttributeValue(action, "Person");
Guid? guidPersonAttribute = personAttributeValue.AsGuidOrNull();
if (guidPersonAttribute.HasValue)
{
var attributePerson = AttributeCache.Read(guidPersonAttribute.Value, rockContext);
if (attributePerson != null || attributePerson.FieldType.Class != "Rock.Field.Types.PersonFieldType")
{
string attributePersonValue = action.GetWorklowAttributeValue(guidPersonAttribute.Value);
if (!string.IsNullOrWhiteSpace(attributePersonValue))
{
Guid personAliasGuid = attributePersonValue.AsGuid();
if (!personAliasGuid.IsEmpty())
{
person = new PersonAliasService(rockContext).Queryable()
.Where(a => a.Guid.Equals(personAliasGuid))
.Select(a => a.Person)
.FirstOrDefault();
if (person == null)
{
errorMessages.Add(string.Format("Person could not be found for selected value ('{0}')!", guidPersonAttribute.ToString()));
return false;
}
}
}
}
}
if (person == null)
{
errorMessages.Add("The attribute used to provide the person was invalid, or not of type 'Person'.");
return false;
}
if (person != null)
{
PersonAliasService personAliasService = new PersonAliasService(rockContext);
personAliasId = person.PrimaryAliasId ?? default(int);
}
//Get DateTime
DateTime currentDateTime = DateTime.Now;
//Get Stars Value
DefinedValueService definedValueService = new DefinedValueService(rockContext);
var type = GetAttributeValue(action, "Type");
Guid typeGuid = type.AsGuid();
var definedValue = definedValueService.GetByGuid(typeGuid);
definedValue.LoadAttributes();
var value = definedValue.GetAttributeValue("StarValue");
var starsValue = Convert.ToDecimal(value);
//Save Stars
SaveStars(currentDateTime, personAliasId, starsValue, definedValue.Value);
return true;
}