Ejemplo n.º 1
0
        public static LongFilter Merge(LongFilter parameter1, LongFilter parameter2)
        {
            if (parameter1 == null)
            {
                parameter1 = new LongFilter();
            }
            if (parameter2 != null)
            {
                if (parameter2.Equal != null)
                {
                    parameter1.Equal = parameter1.Equal;
                }

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

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

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

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

                if (parameter2.GreaterEqual != null)
                {
                    parameter1.GreaterEqual = parameter1.GreaterEqual;
                }
            }
            return(parameter1);
        }
Ejemplo n.º 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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static IQueryable <TSource> Where <TSource, TKey>(this IQueryable <TSource> source, Expression <Func <TSource, TKey> > propertyName, LongFilter filter)
        {
            if (filter.Equal.HasValue)
            {
                source = source.Where(BuildPredicate(propertyName, "==", filter.Equal.Value.ToString()));
            }
            if (filter.NotEqual.HasValue)
            {
                source = source.Where(BuildPredicate(propertyName, "!=", filter.NotEqual.Value.ToString()));
            }
            if (filter.Less.HasValue)
            {
                source = source.Where(BuildPredicate(propertyName, "<", filter.Less.Value.ToString()));
            }
            if (filter.LessEqual.HasValue)
            {
                source = source.Where(BuildPredicate(propertyName, "<=", filter.LessEqual.Value.ToString()));
            }
            if (filter.Greater.HasValue)
            {
                source = source.Where(BuildPredicate(propertyName, ">", filter.Greater.Value.ToString()));
            }
            if (filter.GreaterEqual.HasValue)
            {
                source = source.Where(BuildPredicate(propertyName, ">=", filter.GreaterEqual.Value.ToString()));
            }

            return(source);
        }