public override bool Execute(RockContext rockContext, WorkflowAction action, object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();
            var originAttributeValue = GetActionAttributeValue(action, "Origin");

            var origin = "";
            //first check to see if is attribute
            var cacheTagsGuid = originAttributeValue.AsGuidOrNull();

            if (cacheTagsGuid != null)
            {
                origin = action.GetWorklowAttributeValue(cacheTagsGuid.Value);
            }
            else
            {
                var mergeFields = GetMergeFields(action);
                origin = originAttributeValue.ResolveMergeFields(mergeFields);
            }

            try
            {
                var campusTask = Task.Run(async() => await CampusUtilities.GetClosestCampus(origin));
                campusTask.Wait();

                var campusAttributeValue = GetActionAttributeValue(action, "Campus").AsGuid();
                SetWorkflowAttributeValue(action, campusAttributeValue, campusTask.Result.Guid.ToString());
            }
            catch (Exception e)
            {
                action.AddLogEntry("Exception while trying to load closest campus: " + e.Message, true);
            }


            return(true);
        }
        public async Task <object> GetDistance(int definedValueId, string address)
        {
            var mappable = DefinedValueCache.Get(definedValueId);

            if (mappable == null || mappable.DefinedType.Guid != Constants.UniversalDefinedTypeGuid.AsGuid())
            {
                return(BadRequest("Non valid distance entity"));
            }

            var entityKey = mappable.GetAttributeValue("EntityType");

            switch (entityKey)
            {
            case "Campus":
                return(await CampusUtilities.OrderCampusesByDistance(address));

            case "ParentGroup":
                return(await GetChildGroupDistances(mappable.GetAttributeValue( "EntityId" ).AsInteger(), address));

            case "GroupType":
                return(await GetGroupTypeDistances(mappable.GetAttributeValue( "EntityId" ).AsInteger(), address));

            case "Attribute":
                return(await GetAttributeDistances(mappable.GetAttributeValue( "EntityId" ).AsInteger(), address));

            default:
                break;
            }


            return(BadRequest("Unmappable Entity"));
        }