Example #1
0
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue <TimeSpan>(entity);

            switch (SelectedCondition)
            {
            case Condition.EqualTo:
                return(entityValue == Value);

            case Condition.NotEqualTo:
                return(entityValue != Value);

            case Condition.GreaterThan:
                return(entityValue > Value);

            case Condition.LessThan:
                return(entityValue < Value);

            case Condition.GreaterThanOrEqualTo:
                return(entityValue >= Value);

            case Condition.LessThanOrEqualTo:
                return(entityValue <= Value);

            default:
                throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition));
            }
        }
Example #2
0
 /// <summary>
 /// 输出一个编辑器。
 /// </summary>
 /// <param name="helper">Html帮助器。</param>
 /// <param name="entity">实体对象。</param>
 /// <param name="property">属性元数据。</param>
 /// <returns></returns>
 public static IHtmlContent Editor(this IHtmlHelper helper, IEntity entity, IPropertyMetadata property)
 {
     if (helper == null)
     {
         throw new ArgumentNullException(nameof(helper));
     }
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     if (property == null)
     {
         throw new ArgumentNullException(nameof(property));
     }
     if (helper == null)
     {
         throw new ArgumentNullException("helper");
     }
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     return(Editor(helper, entity, property, property.GetValue(entity)));
 }
        private object GetPropertyMetadataValue(IPropertyMetadata propertyMetadata)
        {
            var value = propertyMetadata.GetValue(this);
            var model = value as BaseViewModel;

            return(model != null?model.ToDictionary() : value);
        }
        protected override object Convert(object value, Type targetType, object parameter)
        {
            var propertyName = parameter as string;

            if (string.IsNullOrEmpty(propertyName))
            {
                return(null);
            }

            try
            {
                var modelBase = value as IModelEditor;
                if (modelBase != null)
                {
                    return(modelBase.GetValue(propertyName));
                }

                if (_propertyMetadata != null)
                {
                    return(_propertyMetadata.GetValue(value));
                }

                if (value != null)
                {
                    return(PropertyHelper.GetPropertyValue(value, propertyName, false));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to get property value '{0}'", propertyName);
            }

            return(null);
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue <TimeSpan>(entity);

            switch (SelectedCondition)
            {
            case Condition.EqualTo:
                return(entityValue == Value);

            case Condition.NotEqualTo:
                return(entityValue != Value);

            case Condition.GreaterThan:
                return(entityValue > Value);

            case Condition.LessThan:
                return(entityValue < Value);

            case Condition.GreaterThanOrEqualTo:
                return(entityValue >= Value);

            case Condition.LessThanOrEqualTo:
                return(entityValue <= Value);

            default:
                throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
            }
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            bool entityValue = propertyMetadata.GetValue<bool>(entity);
            switch (SelectedCondition)
            {
                case Condition.EqualTo:
                    return entityValue == Value;

                default:
                    throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
            }
        }
Example #7
0
        protected virtual async Task UpdateProperty(IValueProvider valueProvider, T entity, IPropertyMetadata property)
        {
            bool   handled  = false;
            bool   hasValue = valueProvider.Keys.Contains(property.ClrName);
            object value;

            if (hasValue)
            {
                if (property.IsFileUpload)
                {
                    value = valueProvider.GetValue <ISelectedFile>(property.ClrName);
                }
                else if (property.Type == CustomDataType.Password)
                {
                    value = valueProvider.GetValue <string>(property.ClrName);
                }
                else
                {
                    value = valueProvider.GetValue(property.ClrName, property.ClrType);
                }
                if (EntityPropertyUpdate != null)
                {
                    var arg = new EntityPropertyUpdateEventArgs <T>(entity, valueProvider, property, value);
                    await EntityPropertyUpdate(Context, arg);

                    handled = arg.IsHandled;
                }
            }
            else
            {
                value = property.GetValue(entity);
            }
            if (!handled)
            {
                if (value != null && !property.ClrType.IsAssignableFrom(value.GetType()))
                {
                    throw new NotImplementedException("未处理的属性“" + property.Name + "”。");
                }
                ValidationContext validationContext = new ValidationContext(entity, Context.DomainContext, null);
                validationContext.MemberName  = property.ClrName;
                validationContext.DisplayName = property.Name;
                var error = property.GetAttributes <ValidationAttribute>().Select(t => t.GetValidationResult(value, validationContext)).Where(t => t != ValidationResult.Success).ToArray();
                if (error.Length > 0)
                {
                    throw new ArgumentException(string.Join(",", error.Select(t => t.ErrorMessage)));
                }
                if (hasValue)
                {
                    property.SetValue(entity, value);
                }
            }
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            bool entityValue = propertyMetadata.GetValue <bool>(entity);

            switch (SelectedCondition)
            {
            case Condition.EqualTo:
                return(entityValue == Value);

            default:
                throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
            }
        }
Example #9
0
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue <string>(entity);

            switch (SelectedCondition)
            {
            case Condition.Contains:
                return(entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1);

            case Condition.EndsWith:
                return(entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase));

            case Condition.EqualTo:
                return(entityValue == Value);

            case Condition.GreaterThan:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) > 0);

            case Condition.GreaterThanOrEqualTo:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) >= 0);

            case Condition.IsEmpty:
                return(entityValue == string.Empty);

            case Condition.IsNull:
                return(entityValue == null);

            case Condition.LessThan:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) < 0);

            case Condition.LessThanOrEqualTo:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) <= 0);

            case Condition.NotEqualTo:
                return(entityValue != Value);

            case Condition.NotIsEmpty:
                return(entityValue != string.Empty);

            case Condition.NotIsNull:
                return(entityValue != null);

            case Condition.StartsWith:
                return(entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase));

            default:
                throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
            }
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue<string>(entity);

            switch (SelectedCondition)
            {
                case Condition.Contains:
                    return entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1;

                case Condition.EndsWith:
                    return entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase);

                case Condition.EqualTo:
                    return entityValue == Value;

                case Condition.GreaterThan:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) > 0;

                case Condition.GreaterThanOrEqualTo:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) >= 0;

                case Condition.IsEmpty:
                    return entityValue == string.Empty;

                case Condition.IsNull:
                    return entityValue == null;

                case Condition.LessThan:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) < 0;

                case Condition.LessThanOrEqualTo:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) <= 0;

                case Condition.NotEqualTo:
                    return entityValue != Value;

                case Condition.NotIsEmpty:
                    return entityValue != string.Empty;

                case Condition.NotIsNull:
                    return entityValue != null;

                case Condition.StartsWith:
                    return entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase);

                default:
                    throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
            }
        }
 /// <summary>
 /// Render a property viewer.
 /// </summary>
 /// <param name="helper">A html helper.</param>
 /// <param name="entity">Entity object.</param>
 /// <param name="property">Property metadata.</param>
 /// <returns></returns>
 public static MvcHtmlString Viewer(this HtmlHelper helper, IEntity entity, IPropertyMetadata property)
 {
     if (helper == null)
     {
         throw new ArgumentNullException("helper");
     }
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     return(Viewer(helper, entity, property, property.GetValue(entity)));
 }
        protected override object Convert(object value, Type targetType, object parameter)
        {
            var propertyName = parameter as string;

            if (string.IsNullOrEmpty(propertyName))
            {
                return(null);
            }

            try
            {
                var modelBase = value as IModelEditor;
                if (modelBase != null)
                {
                    var propertyDataManager = PropertyDataManager.Default;
                    if (propertyDataManager.IsPropertyRegistered(modelBase.GetType(), propertyName))
                    {
#pragma warning disable CS0618 // Type or member is obsolete
                        return(modelBase.GetValueFastButUnsecure(propertyName));

#pragma warning restore CS0618 // Type or member is obsolete
                    }
                }

                if (_propertyMetadata != null)
                {
                    return(_propertyMetadata.GetValue(value));
                }

                if (value != null)
                {
                    return(PropertyHelper.GetPropertyValue(value, propertyName, false));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to get property value '{0}'", propertyName);
            }

            return(null);
        }
Example #13
0
        /// <summary>
        /// Calculates the result
        /// </summary>
        /// <param name="propertyMetadata">
        /// The property metadata
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// <c>True</c> if the entity property value match with the <see cref="Value" /> via <see cref="DataTypeExpression.SelectedCondition" /> operator, otherwise <c>False</c>.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// If <see cref="DataTypeExpression.SelectedCondition" /> is not supported.
        /// </exception>
        public sealed override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue(entity);

            if (!IsNullable && (SelectedCondition == Condition.IsNull || SelectedCondition == Condition.NotIsNull))
            {
                throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition));
            }

            switch (SelectedCondition)
            {
            case Condition.EqualTo:
                return(Equals(entityValue, Value));

            case Condition.GreaterThan:
                return(Comparer.Default.Compare(entityValue, Value) > 0);

            case Condition.GreaterThanOrEqualTo:
                return(Comparer.Default.Compare(entityValue, Value) >= 0);

            case Condition.LessThan:
                return(Comparer.Default.Compare(entityValue, Value) < 0);

            case Condition.LessThanOrEqualTo:
                return(Comparer.Default.Compare(entityValue, Value) <= 0);

            case Condition.NotEqualTo:
                return(!Equals(entityValue, Value));

            case Condition.IsNull:
                return(entityValue == null);

            case Condition.NotIsNull:
                return(entityValue != null);

            default:
                throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition));
            }
        }
Example #14
0
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue <string>(entity);

            if (entityValue == null && propertyMetadata.Type.IsEnumEx())
            {
                var entityValueAsObject = propertyMetadata.GetValue(entity);
                if (entityValueAsObject != null)
                {
                    entityValue = entityValueAsObject.ToString();
                }
            }

            switch (SelectedCondition)
            {
            case Condition.Contains:
                return(entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1);

            case Condition.DoesNotContain:
                return(entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) == -1);

            case Condition.EndsWith:
                return(entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase));

            case Condition.DoesNotEndWith:
                return(entityValue != null && !entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase));

            case Condition.EqualTo:
                return(entityValue == Value);

            case Condition.GreaterThan:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) > 0);

            case Condition.GreaterThanOrEqualTo:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) >= 0);

            case Condition.IsEmpty:
                return(entityValue == string.Empty);

            case Condition.IsNull:
                return(entityValue == null);

            case Condition.LessThan:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) < 0);

            case Condition.LessThanOrEqualTo:
                return(string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) <= 0);

            case Condition.NotEqualTo:
                return(entityValue != Value);

            case Condition.NotIsEmpty:
                return(entityValue != string.Empty);

            case Condition.NotIsNull:
                return(entityValue != null);

            case Condition.StartsWith:
                return(entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase));

            case Condition.DoesNotStartWith:
                return(entityValue != null && !entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase));

            case Condition.Matches:
                return(entityValue != null &&
                       _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value)) &&
                       _regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue));

            case Condition.DoesNotMatch:
                return(entityValue != null &&
                       _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value)) &&
                       !_regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue));

            default:
                throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition));
            }
        }
Example #15
0
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            if (IsNullable)
            {
                var entityValue = propertyMetadata.GetValue <TValue?>(entity);
                switch (SelectedCondition)
                {
                case Condition.EqualTo:
                    return(object.Equals(entityValue, Value));

                case Condition.NotEqualTo:
                    return(!object.Equals(entityValue, Value));

                case Condition.GreaterThan:
                    return(entityValue != null && _comparer.Compare(entityValue.Value, Value) > 0);

                case Condition.LessThan:
                    return(entityValue != null && _comparer.Compare(entityValue.Value, Value) < 0);

                case Condition.GreaterThanOrEqualTo:
                    return(entityValue != null && _comparer.Compare(entityValue.Value, Value) >= 0);

                case Condition.LessThanOrEqualTo:
                    return(entityValue != null && _comparer.Compare(entityValue.Value, Value) <= 0);

                case Condition.IsNull:
                    return(entityValue == null);

                case Condition.NotIsNull:
                    return(entityValue != null);

                default:
                    throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition));
                }
            }
            else
            {
                var entityValue = propertyMetadata.GetValue <TValue>(entity);
                switch (SelectedCondition)
                {
                case Condition.EqualTo:
                    return(object.Equals(entityValue, Value));

                case Condition.NotEqualTo:
                    return(!object.Equals(entityValue, Value));

                case Condition.GreaterThan:
                    return(_comparer.Compare(entityValue, Value) > 0);

                case Condition.LessThan:
                    return(_comparer.Compare(entityValue, Value) < 0);

                case Condition.GreaterThanOrEqualTo:
                    return(_comparer.Compare(entityValue, Value) >= 0);

                case Condition.LessThanOrEqualTo:
                    return(_comparer.Compare(entityValue, Value) <= 0);

                default:
                    throw new NotSupportedException(string.Format(LanguageHelper.GetString("FilterBuilder_Exception_Message_ConditionIsNotSupported_Pattern"), SelectedCondition));
                }
            }
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            var entityValue = propertyMetadata.GetValue<string>(entity);
            if (entityValue == null && propertyMetadata.Type.IsEnumEx())
            {
                var entityValueAsObject = propertyMetadata.GetValue(entity);
                if (entityValueAsObject != null)
                {
                    entityValue = entityValueAsObject.ToString();
                }
            }

            switch (SelectedCondition)
            {
                case Condition.Contains:
                    return entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) != -1;

                case Condition.DoesNotContain:
                    return entityValue != null && entityValue.IndexOf(Value, StringComparison.CurrentCultureIgnoreCase) == -1;

                case Condition.EndsWith:
                    return entityValue != null && entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase);

                case Condition.DoesNotEndWith:
                    return entityValue != null && !entityValue.EndsWith(Value, StringComparison.CurrentCultureIgnoreCase);

                case Condition.EqualTo:
                    return entityValue == Value;

                case Condition.GreaterThan:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) > 0;

                case Condition.GreaterThanOrEqualTo:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) >= 0;

                case Condition.IsEmpty:
                    return entityValue == string.Empty;

                case Condition.IsNull:
                    return entityValue == null;

                case Condition.LessThan:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) < 0;

                case Condition.LessThanOrEqualTo:
                    return string.Compare(entityValue, Value, StringComparison.InvariantCultureIgnoreCase) <= 0;

                case Condition.NotEqualTo:
                    return entityValue != Value;

                case Condition.NotIsEmpty:
                    return entityValue != string.Empty;

                case Condition.NotIsNull:
                    return entityValue != null;

                case Condition.StartsWith:
                    return entityValue != null && entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase);

                case Condition.DoesNotStartWith:
                    return entityValue != null && !entityValue.StartsWith(Value, StringComparison.CurrentCultureIgnoreCase);

                case Condition.Matches:
                    return entityValue != null
                        && _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value))
                        && _regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue);

                case Condition.DoesNotMatch:
                    return entityValue != null
                        && _regexIsValidCache.GetFromCacheOrFetch(Value, () => RegexHelper.IsValid(Value))
                        && !_regexCache.GetFromCacheOrFetch(Value, () => new Regex(Value, RegexOptions.Compiled)).IsMatch(entityValue);

                default:
                    throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
            }
        }
Example #17
0
        /// <summary>
        /// Update property for entity.
        /// </summary>
        /// <param name="entity">Entity to update.</param>
        /// <param name="propertyMetadata">Property metadata.</param>
        /// <returns></returns>
        public async Task UpdateProperty(TEntity entity, IPropertyMetadata propertyMetadata)
        {
            if (propertyMetadata.EditRoles.Count() > 0 &&
                !(propertyMetadata.AuthenticationRequiredMode == AuthenticationRequiredMode.All ?
                  propertyMetadata.EditRoles.All(r => Controller.User.IsInRole(r)) :
                  propertyMetadata.EditRoles.Any(r => Controller.User.IsInRole(r))))
            {
                return;
            }
            if (propertyMetadata.IsFileUpload)
            {
                #region File Path Value
                if (!Controller.Request.Files.AllKeys.Contains(propertyMetadata.ClrName))
                {
                    return;
                }
                if (!(Controller is IFileController <TEntity>))
                {
                    if (propertyMetadata.ClrType != typeof(byte[]))
                    {
                        throw new NotSupportedException("Controller doesn't support upload file.");
                    }
                    if (Controller.Request.Files.AllKeys.Contains(propertyMetadata.ClrName))
                    {
                        var          file   = Controller.Request.Files[propertyMetadata.ClrName];
                        MemoryStream stream = new MemoryStream();
                        await file.InputStream.CopyToAsync(stream);

                        propertyMetadata.SetValue(entity, stream.ToArray());
                        stream.Close();
                        stream.Dispose();
                    }
                }
                else
                {
                    await((IFileController <TEntity>)Controller).SaveFileToProperty(entity, propertyMetadata, Controller.Request.Files[propertyMetadata.ClrName]);
                }
                #endregion
            }
            else
            {
                if (!Controller.Request.Form.AllKeys.Contains(propertyMetadata.ClrName))
                {
                    return;
                }
                string        value     = Controller.Request.Form[propertyMetadata.ClrName];
                TypeConverter converter = EntityValueConverter.GetConverter(propertyMetadata);
                if (converter == null)
                {
                    if (propertyMetadata.ClrType.IsGenericType && propertyMetadata.ClrType.GetGenericTypeDefinition() == typeof(ICollection <>))
                    {
                        converter = new Converter.CollectionConverter();
                    }
                    else if (propertyMetadata.ClrType.IsEnum)
                    {
                        converter = new EnumConverter(propertyMetadata.ClrType);
                    }
                    else
                    {
                        converter = TypeDescriptor.GetConverter(propertyMetadata.ClrType);
                        if (converter == null && propertyMetadata.Type != ComponentModel.DataAnnotations.CustomDataType.Password)
                        {
                            throw new NotSupportedException("Type of \"" + propertyMetadata.ClrName + "\" converter not found.");
                        }
                    }
                }
                if (propertyMetadata.Type == ComponentModel.DataAnnotations.CustomDataType.Password && entity is IPassword)
                {
                    object v = propertyMetadata.GetValue(entity);
                    if (v == null || value != v.ToString())
                    {
                        ((IPassword)entity).SetPassword(value);
                    }
                }
                else
                {
                    EntityValueConverterContext context = new EntityValueConverterContext(EntityBuilder.DescriptorContext, propertyMetadata);
                    object cvalue;
                    try
                    {
                        cvalue = converter.ConvertFrom(context, null, value);
                    }
                    catch (Exception ex)
                    {
                        Controller.ViewBag.ErrorMessage = ex.Message;
                        return;
                    }
                    if (converter.GetType() == typeof(Converter.CollectionConverter))
                    {
                        object collection = propertyMetadata.GetValue(entity);
                        ((dynamic)collection).Clear();
                        var      addMethod = collection.GetType().GetMethod("Add");
                        object[] array     = (object[])cvalue;
                        for (int a = 0; a < array.Length; a++)
                        {
                            addMethod.Invoke(collection, new object[] { array[a] });
                        }
                    }
                    else
                    {
                        propertyMetadata.SetValue(entity, cvalue);
                    }
                }
            }
        }
Example #18
0
        private object GetPropertyMetadataValue(IPropertyMetadata propertyMetadata)
        {
            var value = propertyMetadata.GetValue(this);

            return(value is BaseViewModel model?model.ToDictionary() : value);
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            if (IsNullable)
            {
                var entityValue = propertyMetadata.GetValue<decimal?>(entity);
                switch (SelectedCondition)
                {
                    case Condition.EqualTo:
                        return entityValue == Value;

                    case Condition.NotEqualTo:
                        return entityValue != Value;

                    case Condition.GreaterThan:
                        return entityValue > Value;

                    case Condition.LessThan:
                        return entityValue < Value;

                    case Condition.GreaterThanOrEqualTo:
                        return entityValue >= Value;

                    case Condition.LessThanOrEqualTo:
                        return entityValue <= Value;

                    case Condition.IsNull:
                        return entityValue == null;

                    case Condition.NotIsNull:
                        return entityValue != null;

                    default:
                        throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
                }
            }
            else
            {
                var entityValue = propertyMetadata.GetValue<decimal>(entity);
                switch (SelectedCondition)
                {
                    case Condition.EqualTo:
                        return entityValue == Value;

                    case Condition.NotEqualTo:
                        return entityValue != Value;

                    case Condition.GreaterThan:
                        return entityValue > Value;

                    case Condition.LessThan:
                        return entityValue < Value;

                    case Condition.GreaterThanOrEqualTo:
                        return entityValue >= Value;

                    case Condition.LessThanOrEqualTo:
                        return entityValue <= Value;

                    default:
                        throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
                }
            }
        }
        public override bool CalculateResult(IPropertyMetadata propertyMetadata, object entity)
        {
            if (IsNullable)
            {
                var    entityValue = propertyMetadata.GetValue(entity);
                double doubleValue = 0d;
                if (entityValue != null)
                {
                    doubleValue = Convert.ToDouble(entityValue);
                }
                switch (SelectedCondition)
                {
                case Condition.EqualTo:
                    return(entityValue != null && doubleValue == Value);

                case Condition.NotEqualTo:
                    return(entityValue != null && doubleValue != Value);

                case Condition.GreaterThan:
                    return(entityValue != null && doubleValue > Value);

                case Condition.LessThan:
                    return(entityValue != null && doubleValue < Value);

                case Condition.GreaterThanOrEqualTo:
                    return(entityValue != null && doubleValue >= Value);

                case Condition.LessThanOrEqualTo:
                    return(entityValue != null && doubleValue <= Value);

                case Condition.IsNull:
                    return(entityValue == null);

                case Condition.NotIsNull:
                    return(entityValue != null);

                default:
                    throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
                }
            }
            else
            {
                var entityValue = propertyMetadata.GetValue(entity);
                var doubleValue = Convert.ToDouble(entityValue);
                switch (SelectedCondition)
                {
                case Condition.EqualTo:
                    return(doubleValue == Value);

                case Condition.NotEqualTo:
                    return(doubleValue != Value);

                case Condition.GreaterThan:
                    return(doubleValue > Value);

                case Condition.LessThan:
                    return(doubleValue < Value);

                case Condition.GreaterThanOrEqualTo:
                    return(doubleValue >= Value);

                case Condition.LessThanOrEqualTo:
                    return(doubleValue <= Value);

                default:
                    throw new NotSupportedException(string.Format("Condition '{0}' is not supported.", SelectedCondition));
                }
            }
        }