示例#1
0
        protected virtual string GetPropertyValueInternal(DynamicNode model, string propertyAlias, bool recursive)
        {
            string strValue = "";

            if (model != null && !string.IsNullOrEmpty(propertyAlias))
            {
                IProperty property = null;

                if (!recursive)
                {
                    property = model.GetProperty(propertyAlias);
                }
                else
                {
                    DynamicNode tempModel    = model;
                    IProperty   tempProperty = tempModel.GetProperty(propertyAlias);
                    if (tempProperty != null && !string.IsNullOrEmpty(tempProperty.Value))
                    {
                        property = tempProperty;
                    }

                    while (property == null && tempModel != null && tempModel.Id > 0)
                    {
                        tempModel = tempModel.Parent;
                        if (tempModel != null)
                        {
                            tempProperty = tempModel.GetProperty(propertyAlias);
                            if (tempProperty != null && !string.IsNullOrEmpty(tempProperty.Value))
                            {
                                property = tempProperty;
                            }
                        }
                    }
                }

                if (property != null)
                {
                    strValue = property.Value;
                }
            }

            return(strValue);
        }
        public static string SafeProperty(this DynamicNode node, string propertyName)
        {
            string returnValue = "";

            if (node.HasProperty(propertyName))
            {
                returnValue = node.GetProperty(propertyName).Value as string;
            }

            return(returnValue);
        }
        public static bool IfSafeProperty(this DynamicNode node, string propertyName, out string result)
        {
            string returnValue = "";

            if (node.HasProperty(propertyName))
            {
                returnValue = node.GetProperty(propertyName).Value as string;
            }

            result = returnValue;
            return(!string.IsNullOrEmpty(returnValue));
        }
        public static bool IfSafePropertyMatch(this DynamicNode node, string propertyName, string match)
        {
            bool   returnValue   = false;
            string propertyValue = "";

            if (node.HasProperty(propertyName))
            {
                propertyValue = node.GetProperty(propertyName).Value as string;
                returnValue   = (propertyValue == match);
            }

            return(returnValue);
        }
示例#5
0
        /// <summary>
        /// Gets a property value from Umbraco when a string is expected, nulls are returned as empty string
        /// </summary>
        /// <param name="node"></param>
        /// <param name="alias"></param>
        /// <returns></returns>
        public static string GetStringPropertyValue(this DynamicNode node, string alias)
        {
            string returnValue = string.Empty;

            if (node != null && node.Id != 0)
            {
                var prop = node.GetProperty(alias);

                if (prop != null)
                {
                    returnValue = prop.Value;
                }
            }

            return(returnValue);
        }
示例#6
0
        /// <summary>
        /// Gets a property value from Umbraco when an bool is expected, nulls are returned as false
        /// </summary>
        /// <param name="node"></param>
        /// <param name="alias"></param>
        /// <returns></returns>
        public static bool GetBoolPropertyValue(this DynamicNode node, string alias)
        {
            bool returnValue = false;

            if (node != null && node.Id != 0)
            {
                var prop = node.GetProperty(alias);

                if (prop != null)
                {
                    if (prop.Value == "1")
                    {
                        returnValue = true;
                    }
                }
            }

            return(returnValue);
        }
示例#7
0
        /// <summary>
        /// Gets a property value from Umbraco when an int is expected, nulls are returned as -1
        /// </summary>
        /// <param name="node"></param>
        /// <param name="alias"></param>
        /// <returns></returns>
        public static int GetIntPropertyValue(this DynamicNode node, string alias)
        {
            int returnValue = -1;

            if (node != null && node.Id != 0)
            {
                var prop = node.GetProperty(alias);

                if (prop != null)
                {
                    int intValue = -1;

                    if (int.TryParse(prop.Value, out intValue))
                    {
                        returnValue = intValue;
                    }
                }
            }

            return(returnValue);
        }
        public static IEnumerable <string> ImageUrls(this RazorLibraryCore ctx, DynamicNode node, string alias, string cropProperty, string cropName)
        {
            var mediaProp = node.GetProperty(alias);

            if (mediaProp != null && !string.IsNullOrWhiteSpace(mediaProp.Value))
            {
                if (mediaProp.Value.Contains('<'))
                {
                    foreach (var m in new DynamicXml(mediaProp.Value).OfType <DynamicXml>())
                    {
                        var url = ImageUrlFromXml(ctx, m, cropProperty, cropName);
                        if (!url.IsNullOrWhiteSpace())
                        {
                            yield return(url);
                        }
                    }
                }
                else
                {
                    //we look like a list ofr ids
                    foreach (var val in mediaProp.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        int mediaId = 0;
                        if (int.TryParse(val, out mediaId))
                        {
                            var url = ImageUrlFromMediaItem(ctx, mediaId, cropProperty, cropName);
                            if (!url.IsNullOrWhiteSpace())
                            {
                                yield return(url);
                            }
                        }
                    }
                    //we look like xml
                }
            }
        }