Esempio n. 1
0
        internal void CreateColumnParameters(object entity)
        {
            var properties =
                entity
                .GetType()
                .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                .Where(x => x.GetValue(entity) != null)?
                .ToArray();

            foreach (var property in properties)
            {
                if (property.GetCustomAttribute <EncryptAttribute>(false) != null &&
                    property.PropertyType == typeof(string))
                {
                    property.SetValue(entity, Encryption.Encrypt(Convert.ToString(property.GetValue(entity)), true));
                }
            }

            this.ColumnNames      = string.Join(", ", properties?.Select(x => x.Name));
            this.ColumnParameters = string.Join(", ", properties?.Select(x => $"{Param}{this.OptionalName}{x.Name}"));
            this.ColumnValues     = string.Join(", ", properties?.Select(x => { return($"{x.Name} = {Param}{this.OptionalName}{x.Name}"); }));
            this.Parameters       =
                entity.ToDictionary(this.OptionalName)
                .Where(x => x.Value != null)
                .ToDictionary(x => x.Key, x => x.Value);

            foreach (var property in this.Parameters.ToList())
            {
                this.Parameters[property.Key] = ConvertToSafe.Convert(property.Value);
            }
        }
Esempio n. 2
0
        public void WhereUniversal(Operator?oper, string where, object value)
        {
            if (value == null)
            {
                value = DBNull.Value;
            }

            var columnParameter = $"{this.OptionalName}custom{this.ColumnCount}";
            var statement       = string.Format(where, this.Param + columnParameter) + " ";

            this.AddWhere(oper, statement);
            this.Parameters.Add(columnParameter, ConvertToSafe.Convert(value));
            this.ColumnCount++;
        }
Esempio n. 3
0
        public void Where(
            Operator?oper,
            TableColumn column,
            Is condition,
            object value)
        {
            if (column == null)
            {
                return;
            }

            if (value == null)
            {
                value = DBNull.Value;
            }

            string columnParameter = this.OptionalName + column.Get + this.ColumnCount;
            string statement       = string.Empty;

            if (!column.Property.PropertyType.IsArray)
            {
                statement = $"{column.Get} {GetCondition(condition)} {Param}{columnParameter} ";
            }
            else
            {
                statement = $"{Param}{columnParameter} {GetCondition(condition)} ANY({column.Get}) ";
            }

            this.AddWhere(oper, statement);

            var property = typeof(TableEntity).GetProperty(column.ColumnName);

            if (column.Property.GetCustomAttribute <EncryptAttribute>() != null &&
                column.Property.PropertyType == typeof(string))
            {
                value = Encryption.Encrypt(Convert.ToString(value), true);
            }

            value = ConvertToSafe.Convert(value);

            this.Parameters.Add(columnParameter, value);
            this.ColumnCount++;
        }