Rock.Model.DefinedValueService.GetByGuid C# (CSharp) Method

GetByGuid() public method

Returns a Rock.Model.DefinedValue by its Guid identifier.
public GetByGuid ( Guid guid ) : DefinedValue
guid Guid A representing the Guid identifier of the to retrieve.
return DefinedValue
        public DefinedValue GetByGuid( Guid guid )
        {
            return Queryable().FirstOrDefault( t => t.Guid == guid );
        }

Usage Example

Ejemplo n.º 1
0
        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;
        }