Пример #1
0
        public static StringFilter Merge(StringFilter parameter1, StringFilter parameter2)
        {
            if (parameter1 == null)
            {
                parameter1 = new StringFilter();
            }
            if (parameter2 != null)
            {
                if (parameter2.Equal != null)
                {
                    parameter1.Equal = parameter1.Equal;
                }

                if (parameter2.NotEqual != null)
                {
                    parameter1.NotEqual = parameter1.NotEqual;
                }

                if (parameter2.Contain != null)
                {
                    parameter1.Contain = parameter1.Contain;
                }

                if (parameter2.NotContain != null)
                {
                    parameter1.NotContain = parameter1.NotContain;
                }

                if (parameter2.StartWith != null)
                {
                    parameter1.StartWith = parameter1.StartWith;
                }

                if (parameter2.NotStartWith != null)
                {
                    parameter1.NotStartWith = parameter1.NotStartWith;
                }

                if (parameter2.EndWith != null)
                {
                    parameter1.EndWith = parameter1.EndWith;
                }

                if (parameter2.NotEndWith != null)
                {
                    parameter1.NotEndWith = parameter1.NotEndWith;
                }
            }
            return(parameter1);
        }
Пример #2
0
        public FilterPermissionDefinition(string name, long FieldTypeId, long PermissionOperatorId, string value)
        {
            this.Name        = name;
            this.FieldTypeId = FieldTypeId;
            if (FieldTypeId == FieldTypeEnum.ID.Id)
            {
                if (IdFilter == null)
                {
                    IdFilter = new IdFilter();
                }
                if (long.TryParse(value, out long result))
                {
                    if (PermissionOperatorId == PermissionOperatorEnum.ID_EQ.Id)
                    {
                        IdFilter.Equal = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.ID_NE.Id)
                    {
                        IdFilter.NotEqual = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.ID_IN.Id)
                    {
                        if (IdFilter.In == null)
                        {
                            IdFilter.In = new List <long>
                                              ();
                        }
                        IdFilter.In.Add(result);
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.ID_NI.Id)
                    {
                        if (IdFilter.NotIn == null)
                        {
                            IdFilter.NotIn = new List <long>
                                                 ();
                        }
                        IdFilter.NotIn.Add(result);
                    }
                }
            }

            if (FieldTypeId == FieldTypeEnum.GUID.Id)
            {
                if (GuidFilter == null)
                {
                    GuidFilter = new GuidFilter();
                }
                if (Guid.TryParse(value, out Guid result))
                {
                    if (PermissionOperatorId == PermissionOperatorEnum.GUID_EQ.Id)
                    {
                        GuidFilter.Equal = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.GUID_NE.Id)
                    {
                        GuidFilter.NotEqual = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.GUID_IN.Id)
                    {
                        if (GuidFilter.In == null)
                        {
                            GuidFilter.In = new List <Guid>
                                                ();
                        }
                        GuidFilter.In.Add(result);
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.GUID_NI.Id)
                    {
                        if (GuidFilter.NotIn == null)
                        {
                            GuidFilter.NotIn = new List <Guid>
                                                   ();
                        }
                        GuidFilter.NotIn.Add(result);
                    }
                }
            }

            if (FieldTypeId == FieldTypeEnum.STRING.Id)
            {
                if (StringFilter == null)
                {
                    StringFilter = new StringFilter();
                }
                if (string.IsNullOrWhiteSpace(value))
                {
                    string result = value;
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_EQ.Id)
                    {
                        StringFilter.Equal = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_NE.Id)
                    {
                        StringFilter.NotEqual = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_SW.Id)
                    {
                        StringFilter.StartWith = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_NSW.Id)
                    {
                        StringFilter.NotStartWith = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_EW.Id)
                    {
                        StringFilter.EndWith = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_NEW.Id)
                    {
                        StringFilter.NotEndWith = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_CT.Id)
                    {
                        StringFilter.Contain = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.STRING_NC.Id)
                    {
                        StringFilter.NotContain = result;
                    }
                }
            }

            if (FieldTypeId == FieldTypeEnum.LONG.Id)
            {
                if (LongFilter == null)
                {
                    LongFilter = new LongFilter();
                }
                if (long.TryParse(value, out long result))
                {
                    if (PermissionOperatorId == PermissionOperatorEnum.LONG_EQ.Id)
                    {
                        LongFilter.Equal = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.LONG_NE.Id)
                    {
                        LongFilter.NotEqual = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.LONG_GT.Id)
                    {
                        if (LongFilter.Greater == null || LongFilter.Greater > result)
                        {
                            LongFilter.Greater = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.LONG_GE.Id)
                    {
                        if (LongFilter.GreaterEqual == null || LongFilter.GreaterEqual >= result)
                        {
                            LongFilter.GreaterEqual = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.LONG_LT.Id)
                    {
                        if (LongFilter.Less == null || LongFilter.Less < result)
                        {
                            LongFilter.Less = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.LONG_LE.Id)
                    {
                        if (LongFilter.LessEqual == null || LongFilter.LessEqual <= result)
                        {
                            LongFilter.LessEqual = result;
                        }
                    }
                }
            }

            if (FieldTypeId == FieldTypeEnum.DECIMAL.Id)
            {
                if (DecimalFilter == null)
                {
                    DecimalFilter = new DecimalFilter();
                }
                if (decimal.TryParse(value, out decimal result))
                {
                    if (PermissionOperatorId == PermissionOperatorEnum.DECIMAL_EQ.Id)
                    {
                        DecimalFilter.Equal = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DECIMAL_NE.Id)
                    {
                        DecimalFilter.NotEqual = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DECIMAL_GT.Id)
                    {
                        if (DecimalFilter.Greater == null || DecimalFilter.Greater > result)
                        {
                            DecimalFilter.Greater = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DECIMAL_GE.Id)
                    {
                        if (DecimalFilter.GreaterEqual == null || DecimalFilter.GreaterEqual >= result)
                        {
                            DecimalFilter.GreaterEqual = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DECIMAL_LT.Id)
                    {
                        if (DecimalFilter.Less == null || DecimalFilter.Less < result)
                        {
                            DecimalFilter.Less = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DECIMAL_LE.Id)
                    {
                        if (DecimalFilter.LessEqual == null || DecimalFilter.LessEqual <= result)
                        {
                            DecimalFilter.LessEqual = result;
                        }
                    }
                }
            }

            if (FieldTypeId == FieldTypeEnum.DATE.Id)
            {
                if (DateFilter == null)
                {
                    DateFilter = new DateFilter();
                }
                if (DateTime.TryParse(value, out DateTime result))
                {
                    if (PermissionOperatorId == PermissionOperatorEnum.DATE_EQ.Id)
                    {
                        DateFilter.Equal = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DATE_NE.Id)
                    {
                        DateFilter.NotEqual = result;
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DATE_GT.Id)
                    {
                        if (DateFilter.Greater == null || DateFilter.Greater > result)
                        {
                            DateFilter.Greater = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DATE_GE.Id)
                    {
                        if (DateFilter.GreaterEqual == null || DateFilter.GreaterEqual >= result)
                        {
                            DateFilter.GreaterEqual = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DATE_LT.Id)
                    {
                        if (DateFilter.Less == null || DateFilter.Less < result)
                        {
                            DateFilter.Less = result;
                        }
                    }
                    if (PermissionOperatorId == PermissionOperatorEnum.DATE_LE.Id)
                    {
                        if (DateFilter.LessEqual == null || DateFilter.LessEqual <= result)
                        {
                            DateFilter.LessEqual = result;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static IQueryable <TSource> Where <TSource, TKey>(this IQueryable <TSource> source, Expression <Func <TSource, TKey> > propertyName, StringFilter filter)
        {
            if (!string.IsNullOrEmpty(filter.Equal))
            {
                source = source.Where(BuildPredicate(propertyName, "==", filter.Equal));
            }

            if (!string.IsNullOrEmpty(filter.NotEqual))
            {
                source = source.Where(BuildPredicate(propertyName, "!=", filter.NotEqual));
            }

            if (!string.IsNullOrEmpty(filter.Contain))
            {
                source = source.Where(BuildPredicate(propertyName, "Contains", filter.Contain));
            }

            if (!string.IsNullOrEmpty(filter.NotContain))
            {
                source = source.Where(BuildPredicate(propertyName, "NotContains", filter.NotContain));
            }

            if (!string.IsNullOrEmpty(filter.StartWith))
            {
                source = source.Where(BuildPredicate(propertyName, "StartsWith", filter.StartWith));
            }

            if (!string.IsNullOrEmpty(filter.NotStartWith))
            {
                source = source.Where(BuildPredicate(propertyName, "NotStartsWith", filter.NotStartWith));
            }

            if (!string.IsNullOrEmpty(filter.EndWith))
            {
                source = source.Where(BuildPredicate(propertyName, "EndsWith", filter.EndWith));
            }

            if (!string.IsNullOrEmpty(filter.NotEndWith))
            {
                source = source.Where(BuildPredicate(propertyName, "NotEndsWith", filter.NotEndWith));
            }
            return(source);
        }