Esempio n. 1
0
        private string ValueConverter(object value)
        {
            if (value == null)
            {
                return("NULL");
            }

            if (value.GetType().IsSubclassOf(typeof(DateTime)) || value is DateTime)
            {
                return("'" + DateTimeUtility.GetSqlFormatDate((DateTime)value) + "'");
            }

            if ((value.GetType().IsSubclassOf(typeof(long)) || value is long) ||
                (value.GetType().IsSubclassOf(typeof(int)) || value is int) ||
                (value.GetType().IsSubclassOf(typeof(short)) || value is short) ||
                (value.GetType().IsSubclassOf(typeof(double)) || value is double) ||
                (value.GetType().IsSubclassOf(typeof(float)) || value is float))
            {
                return(value.ToString());
            }

            if (value.GetType().IsSubclassOf(typeof(string)) || value is string)
            {
                return("'" + value.ToString() + "'");
            }

            if (value.GetType().IsSubclassOf(typeof(bool)) || value is bool)
            {
                if ((bool)value == true)
                {
                    return("1");
                }
                return("0");
            }

            if (value.GetType().IsSubclassOf(typeof(IModel)) || value is IModel)
            {
                return(((IModel)value).UniqueIdentifierValue);
            }

            if (value.GetType().IsSubclassOf(typeof(Enum)))
            {
                return(((int)value).ToString());
            }

            throw new ApiException("Invalid value for invoking to database");
        }